Create an array of initial size (v5)

Revision 5 of this benchmark created on


Setup

var arr, size = 1e3, undef;

Test runner

Ready to run.

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

Revisions

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