Array direct assignment vs push

JavaScript performance comparison

Revision 169 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array = new Array(1000);
  
  const merge = (
    a,
    b
  ) => {
    const arr = [];
    let index = 0;
    for (let i = 0; i < a.length; i++) {
      arr[index++] = a[i];
    }
    for (let i = 0; i < b.length; i++) {
      arr[index++] = a[i];
    }
    return arr;
  };
  

};
</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
Push
for(var i = 0; i < 100; i++)
{
  array = array.concat([1, 2, 3, 4, 5, 6]);
}
pending…
Direct assignment
for(var i = 0; i < 100; i++)
{
  array = merge(array, [1, 2, 3, 4, 5, 6]);
}
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