Range from 0 to 1e6

Benchmark created on


Setup

let n = 1e6;

Teardown

delete array;
delete n;
delete out;

Test runner

Ready to run.

Testing in
TestOps/sec
Fill, then map
let out = Array(n).fill(-1).map((e, i) => i);
ready
Fill, then for loop
let array = Array(n);
array.fill(-1);
for (let i = 0; i < n; i++) {
	array[i] = i;
}
ready
For loop over sparse
let array = Array(n);
for (let i = 0; i < n; i++) {
	array[i] = i;
}
ready
Push elements to array
let array = Array();
for (let i = 0; i < n; i++) {
	array.push(i);
}
ready
Array.from
let out = Array.from({ length: n}, (_, i) => i);
ready

Revisions

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