Array preallocation performance

JavaScript performance comparison

Revision 6 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    window.growFactor = 1000;
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
for-loop Fill (1x)
var arr = [],
    l = window.growFactor;
arr.length = l;
for (var i = 0; i < l; ++i) {
  arr[i] = 0;
}
pending…
for-loop Fill (1x; Not initialized))
var arr = [],
    l = window.growFactor;
for (var i = 0; i < l; ++i) {
  arr[i] = 0;
}
pending…
for-loop Fill (65x)
var arr = [],
    l = 65 * window.growFactor;
arr.length = l;
for (var i = 0; i < l; ++i) {
  arr[i] = 0;
}
pending…
for-loop Fill (65x; Not initialized)
var arr = [],
    l = 65 * window.growFactor;
for (var i = 0; i < l; ++i) {
  arr[i] = 0;
}
pending…
for-loop Fill (65x) alt initialized
var arr = new Array(65 * window.growFactor)    
for (var i = 0; i < arr.length; ++i) {
  arr[i] = 0;
}
pending…
for-loop Fill (65x) alt not initialized
l = 100*window.growFactor;
var arr = new Uint8Array(l);
   
for (var i = 0; i < l; ++i) {
  arr[i] = 0;
}
pending…
for-loop Fill (1x) alt
l = window.growFactor;
var arr = new Uint8Array(l);
   
for (var i = 0; i < l; ++i) {
  arr[i] = 0;
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment