Map a new range of indices

Benchmark created on


Description

Creating and mapping a range of indices 0..length to new values

Setup

const length = 1000

Test runner

Ready to run.

Testing in
TestOps/sec
Array.from({ length }, mapper)
const evenNumbers = Array.from({ length }, (_, i) => i * 2)
ready
Array.from({ length }).map
const evenNumbers = Array.from({ length }).map((_, i) => i * 2)
ready
[...Array(length).keys()].map
const evenNumbers = [...Array(length).keys()].map(i => i * 2)
ready
Array(length).fill(null).map
const evenNumbers = Array(length).fill(null).map((_, i) => i * 2)
ready
Array(length).fill(0).map
const evenNumbers = Array(length).fill(0).map((_, i) => i * 2)
ready
Array(length).fill(false).map
const evenNumbers = Array(length).fill(false).map((_, i) => i * 2)
ready
Array(length).fill().map
const evenNumbers = Array(length).fill().map((_, i) => i * 2)
ready
for loop
const evenNumbers = []
for (let i = 0; i < length; i++) {
	evenNumbers.push(i * 2)
}
ready

Revisions

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