preallocating Array

JavaScript performance comparison

Revision 30 of this test case created by

Preparation code

<script>
  var N = 1000;
  var dummy = new Array(N); // prevents garbage collecting hidden class in Chrome
</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
[].length
var a = [];
a.length = N;
for (var i = 0; i < N; ++i) {
 a[i] = Math.random() > 0.5 ? "foo" : 3;
}
// .push on new Array(N) appends elements after N index.
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments