Array direct assignment vs push

JavaScript performance comparison

Revision 112 of this test case created by

Preparation code

<script>
var arr = reset(),
    val;
function reset () {
    return 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
Push
var arr = reset();
arr.push(val);
arr.push(val);
arr.push(val);
pending…
Increase length then assign
var arr = reset(),
  len = arr.length;

arr.length = len + 3;

arr[len] = val;
arr[len + 1] = val;
arr[len + 2] = val;
pending…
Direct assignment
var arr = reset();
arr[arr.length] = val;
arr[arr.length] = val;
arr[arr.length] = val;
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