Javascript array concat vs push

JavaScript performance comparison

Revision 49 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr1 = [0, 1, 2, 3, 4];
  
  var arr2 = [];
  
  var i = 0;
  
  var j = 0;

};
</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
concat
arr2.concat(arr1);
pending…
push dynamic
var arr1Length = arr1.length;
for (j = 0; j < arr1Length; ++j)
  arr2.push(arr1[j]);
pending…
push static
arr2.push(arr1[0]);
arr2.push(arr1[1]);
arr2.push(arr1[2]);
arr2.push(arr1[3]);
arr2.push(arr1[4]);
pending…
assignment
arr2[0] = arr1[0];
arr2[1] = arr1[1];
arr2[2] = arr1[2];
arr2[3] = arr1[3];
arr2[4] = arr1[4];
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