push allocated vs dynamic (v33)

Revision 33 of this benchmark created on


Description

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

Setup

var n = 10000;

Test runner

Ready to run.

Testing in
TestOps/sec
push
var myArray = [];
for (var i = 0; i < n; i++) {
  myArray.push(i)
}
ready
forward writing
var myArray = [];
for (var i = 0; i < n; i++) {
  myArray[i] = i
}
ready
reverse writing, array allocated with Array constructor
var i = n;
var myArray = Array(n);
while (i--) {
  myArray[i] = i
}
ready
Array Constructor Forward
var myArray = Array(n);
for (var i = 0; i < n; i++) {
  myArray[i] = i
}
ready
reverse writing, array not allocated with Array constructor
var i = n;
var myArray = [];
while (i--) {
  myArray[i] = i
}
ready

Revisions

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