Script Preparation code:
Tests:

Historical Performance Data aggregated from 33 community runs

Desktop Results:
Chrome 24 runs
Array(n).fill(undefined)
4K/s
Array.apply(null, { length: 4 })
487/s
[...Array(n).keys()].map(k => undefined)
103/s
Array.from
94/s
for loop push
86/s

Fastest: Array(n).fill(undefined) (47.4x faster)

View exact numbers
  • Array(n).fill(undefined): 4,074 ops/sec
  • Array.apply(null, { length: 4 }): 487 ops/sec
  • [...Array(n).keys()].map(k => undefined): 103 ops/sec
  • Array.from: 94 ops/sec
  • for loop push: 86 ops/sec
Firefox 9 runs
for loop push
3K/s
Array(n).fill(undefined)
2K/s
Array.from
1K/s
[...Array(n).keys()].map(k => undefined)
595/s
Array.apply(null, { length: 4 })
427/s

Fastest: for loop push (6.3x faster)

View exact numbers
  • for loop push: 2,704 ops/sec
  • Array(n).fill(undefined): 2,122 ops/sec
  • Array.from: 1,037 ops/sec
  • [...Array(n).keys()].map(k => undefined): 595 ops/sec
  • Array.apply(null, { length: 4 }): 427 ops/sec

Results show median performance across all community submissions. Run this benchmark yourself to verify on your device.

Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results
  • Test case name Result
    [...Array(n).keys()].map(k => undefined)
    Array.apply(null, { length: 4 })
    Array.from
    Array(n).fill(undefined)
    for loop push

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 months ago)
Mozilla/5.0 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0
Firefox 148 on Linux
View result in a separate tab
Array(n).fill(undefined)
2K/s
for loop push
792/s
Array.from
720/s
[...Array(n).keys()].map(k => undefined)
349/s
Array.apply(null, { length: 4 })
269/s
View exact numbers
Test name Executions per second
Array(n).fill(undefined) 2,122 Ops/sec
for loop push 792 Ops/sec
Array.from 720 Ops/sec
[...Array(n).keys()].map(k => undefined) 349 Ops/sec
Array.apply(null, { length: 4 }) 269 Ops/sec