Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Chrome 121
Windows
Desktop
2 years ago
[...Array(n)]
10K/s
Array(n).fill(null)
10K/s
while(up--) myArray.push(Math.random());
10K/s
Array.from({ length: n })
8K/s
Array.from({ length:n }, (item, i) => i)
7K/s
View exact numbers
Test name Executions per second
[...Array(n)] 9,981 Ops/sec
Array(n).fill(null) 9,944 Ops/sec
while(up--) myArray.push(Math.random()); 9,672 Ops/sec
Array.from({ length: n }) 7,529 Ops/sec
Array.from({ length:n }, (item, i) => i) 7,080 Ops/sec
Tests: