pre-allocated arrays (v43)

Revision 43 of this benchmark created by Oscar Campbell on


Setup

predefinedCorrectLengthArray = new Array(10);

Test runner

Ready to run.

Testing in
TestOps/sec
empty literal
var arr = [];
for (var i = 0; i < 10; i++) {
    arr[i] = i;
}
ready
pre-allocated array (sparse)
var arr = new Array(10);
for (var i = 0; i < 10; i++) {
    arr[i] = i;
}
ready
pre-allocated array (dense)
var arr = Array.apply(null, new Array(10));
for (var i = 0; i < 10; i++) {
    arr[i] = i;
}
ready
pre-allocated array - omit new keyword
var arr = Array(10);
for (var i = 0; i < 10; i++) {
    arr[i] = i;
}
ready
empty literal, push()
var arr = [];
for (var i = 0; i < 10; i++) {
    arr.push(i);
}
ready
clone array and replace
var arr = predefinedCorrectLengthArray.slice();
for (var i = 0; i < 10; i++) {
    arr[i] = i;
}
ready

Revisions

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