Native trim vs Regex trim vs mixed

JavaScript performance comparison

Test case created by mrchief

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for (var i = 0; i < 10; i++) arr.push("  str" + i + "  ");

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Native trim
arr.map(Function.prototype.call, String.prototype.trim);
pending…
Regex Trim
arr.map(function(s) {
  return s.replace(/^\s+|\s+$/g, '');
});
pending…
Native trim without Function.call
arr.map(function(s) {
  return s.trim();
});
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments