Create array of length N

Benchmark created on


Setup

function makeArrayForLoop(N, map) {
	const arr = Array(N);
	for (let i = 0; i < arr.length; i++) {
		arr[i] = map(undefined, i);
	}
	return arr;
}

Test runner

Ready to run.

Testing in
TestOps/sec
makeArrayForLoop
makeArrayForLoop(2000, (_, i) => i);
ready
Array.from
Array.from({length: 2000}).map((_, i) => i);
ready
Array.fill.map
Array(2000).fill().map((_, i) => i);
ready

Revisions

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