Array#push vs Array#concat vs for loop

JavaScript performance comparison

Test case created by a_bicky

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array1 = [];
  var array2 = [];
  for (var i = 0; i < 1000; i++) {
    array1[i] = i;
    array2[i] = 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
Array#push
var array = array1.slice();
Array.prototype.push.apply(array, array2);
pending…
Array#concat
var array = array1.slice();
array = array.concat(array2);
pending…
for loop
var array = array1.slice();
for (var i = 0, len = array2.length; i < len; i++) {
  array.push(array2[i]);
}
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