push allocated vs dynamic (v41)

Revision 41 of this benchmark created by somebody on


Description

is it usefull to pre-allocate the array by setting the last value first when assigning some values ?

Setup

var n=10000;
    var myArray = [];

Test runner

Ready to run.

Testing in
TestOps/sec
push
myArray.length = 0;

for (var i = 0; i < n; i++) {
    myArray.push(i);
}
ready
forward writing
myArray.length = 0;

for (var i = 0; i < n; i++) {
    myArray[i] = i;
}
ready
reverse writing
myArray.length = 0;

for (var i = n - 1; i > -1; i--) {
    myArray[i] = i;
}
ready

Revisions

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