how much does preallocation help? (v3)

Revision 3 of this benchmark created on


Setup

var array = [...new Array(1000000)].map(a => String.fromCharCode(a));

Test runner

Ready to run.

Testing in
TestOps/sec
Preallocated
const newArray = new Array(array.length);
array.forEach((item, index) => newArray[index] = item);
ready
Dynamically indexed out of bounds
const newArray = [];
array.forEach((item, index) => newArray[index] = item);
ready
Push
const newArray = [];
array.forEach((item, index) => newArray.push(item));
ready

Revisions

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