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
while(up--) myArray.push(Math.random());
5K/s
Array(n).fill(null)
5K/s
[...Array(n)]
5K/s
Array.from({ length: n })
4K/s
Array.from({ length:n }, (item, i) => i)
4K/s
View exact numbers
Test name Executions per second
while(up--) myArray.push(Math.random()); 5,330 Ops/sec
Array(n).fill(null) 5,253 Ops/sec
[...Array(n)] 5,191 Ops/sec
Array.from({ length: n }) 4,117 Ops/sec
Array.from({ length:n }, (item, i) => i) 3,967 Ops/sec
Tests: