Tests:

Historical Performance Data aggregated from 5 community runs

Desktop Results:
Chrome 5 runs
Array(n).fill(null)
11K/s
[...Array(n)]
11K/s
while(up--) myArray.push(Math.random());
10K/s
Array.from({ length: n })
8K/s
Array.from({ length:n }, (item, i) => i)
7K/s

Fastest: Array(n).fill(null) (1.5x faster)

View exact numbers
  • Array(n).fill(null): 10,808 ops/sec
  • [...Array(n)]: 10,625 ops/sec
  • while(up--) myArray.push(Math.random());: 10,129 ops/sec
  • Array.from({ length: n }): 7,852 ops/sec
  • Array.from({ length:n }, (item, i) => i): 7,369 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)]
    Array(n).fill(null)
    Array.from({ length: n })
    Array.from({ length:n }, (item, i) => i)
    while(up--) myArray.push(Math.random());

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 months ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Chrome 145 on Linux
View result in a separate tab
Array(n).fill(null)
109K/s
[...Array(n)]
108K/s
while(up--) myArray.push(Math.random());
60K/s
Array.from({ length: n })
21K/s
Array.from({ length:n }, (item, i) => i)
20K/s
View exact numbers
Test name Executions per second
Array(n).fill(null) 108,739 Ops/sec
[...Array(n)] 107,696 Ops/sec
while(up--) myArray.push(Math.random()); 60,162 Ops/sec
Array.from({ length: n }) 20,517 Ops/sec
Array.from({ length:n }, (item, i) => i) 20,048 Ops/sec