Append string vs join array

JavaScript performance comparison

Revision 12 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var i = 0,
      str = '',
      arr = [],
      w1 = 'brown',
      w2 = 'jumped',
      w3 = 'lazy';

};
</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
array join bad
arr = [];
for (var i = 0; i < 100; i++) {
  arr[i++] = 'Quick ';
  arr[i++] = w1;
  arr[i++] = ' fox ';
  arr[i++] = w2;
  arr[i++] = ' over the ';
  arr[i++] = w3;
  arr[i++] = ' dog. ';
  arr.join('');
}
pending…
String contcat
str = '';
for (var i = 0; i < 100; i++) {
  str += 'Quick ';
  str += w1;
  str += ' fox ';
  str += w2;
  str += ' over the ';
  str += w3;
  str += ' dog. ';
}
pending…
Array join #2
arr = [];
for (var j = 0; j < 100; j++) {
  arr.push('Quick ', w1, ' fox ', w2, ' over the ', w3, ' dog. ');
}
arr.join();
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