Array direct assignment vs push

JavaScript performance comparison

Revision 52 of this test case created by jamarr81

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var array = [];

};
</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
var data = "test";
for(var i = 0; i < 100; i++)
{
  array[i] = data;
}
pending…
Push
var data = "test";
for(var i = 0; i < 100; i++)
{
  array.push(data);
}
pending…
Direct assignment (calculated)
var data = "test";
for(var i = 0; i < 100; i++)
{
  array[array.length] = data;
}
pending…
Push (multi)
var data = "test";
for(var i = 0; i < 100; i += 5)
{
  array.push(data, data, data, data, data);
}
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