Filling the array (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Regular creation
let a = [];
for (let i = 0; i < Math.pow(10, 3); i++) {
	a.push(i);
}
ready
Preallocation
let size = Math.pow(10, 3);
let a = new Array(size);
for (let i = 0; i < size; i++) {
	a[i] = i;
}
ready
Preallocation #2
let a = [];
a.length = Math.pow(10, 3);
for (let i = 0; i < a.length; i++) {
	a[i] = i;
}
ready

Revisions

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