Create an array of initial size and fill it (v3)

Revision 3 of this benchmark created on


Setup

var arr, size = 1e3, Math.random();

Test runner

Ready to run.

Testing in
TestOps/sec
Array constructor
arr = Array(size);
ready
for loop + push
arr = [];
for (var i = 0; i < size; ++i) {
  arr[i] = undef;
}
 
ready
while loop, forwards
var i = 0;
arr = [];
while (i++ < size) {
    arr[i] = undef;
}
ready
while loop, backwards
var i = size;
arr = [];
while (i-- > 0) {
    arr[i] = undef;
}
ready
sparse array
arr = [];
arr[size - 1] = undef;
ready
length
arr = [];
arr.length = size;
ready

Revisions

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