Array direct assignment vs push

JavaScript performance comparison

Revision 122 of this test case created by Favian

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array1 = [];
  
  var array2 = [];
  array2.length = 100;
  
  var array3 = new Array(100);

};
</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
Direct assignment (empty literal array)
for(var i = 0; i < 100; i++)
{
  array1[i] = "test";
}
pending…
Push
for(var i = 0; i < 100; i++)
{
  array1.push("test");
}
pending…
Direct assignment (calculated)
for(var i = 0; i < 100; i++)
{
  array1[array1.length] = "test";
}
pending…
Direct assignment (literal array with length set)
for(var i = 0; i < 100; i++)
{
  array2[i] = "test";
}
pending…
Direct assignment (constructor array)
for(var i = 0; i < 100; i++)
{
  array3[i] = "test";
}
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