Create an array of initial size

Benchmark created by LJHarb on


Setup

var arr, size = 1e3, undef;

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

Revisions

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