Array direct assignment vs push

JavaScript performance comparison

Revision 81 of this test case created by jerp

Preparation code


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

};
</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
for (direct)
for (var i = 0; i < 100; i++) {
  array[i] = i;
}
pending…
for (push)
for (var i = 0; i < 100; i++) {
  array.push(i);
}
pending…
for (length)
for (var i = 0; i < 100; i++) {
  array[array.length] = i;
}
pending…
while (direct)
while (++j < 100) {
  array[j] = j;
}
pending…
while (push)
while (++j < 100) {
  array.push(j);
}
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