Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Chrome 122
Windows
Desktop
2 years ago
[...Array(n)]
11K/s
Array(n).fill(null)
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
View exact numbers
Test name Executions per second
[...Array(n)] 10,987 Ops/sec
Array(n).fill(null) 10,942 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
Tests: