Script Preparation code:
AخA
 
var n = 100000; // 100k
Tests:
  • [...Array(n).keys()].map(k => undefined)

     
    [...Array(n).keys()].map(k => undefined);
  • Array.apply(null, { length: 4 })

     
     Array.apply(null, { length: n });
  • Array.from

     
    Array.from({ length: n }, () => undefined);
  • Array(n).fill(undefined)

     
    Array(n).fill(undefined)
  • for loop push

     
    const arr = [];
    for (let i = 0; i < n; i++) {
      arr.push(undefined);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • 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: 18 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Chrome 134 on Windows
View result in a separate tab
Test name Executions per second
[...Array(n).keys()].map(k => undefined) 440.9 Ops/sec
Array.apply(null, { length: 4 }) 866.8 Ops/sec
Array.from 481.8 Ops/sec
Array(n).fill(undefined) 5579.1 Ops/sec
for loop push 1232.7 Ops/sec