Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Initializing array with n undefined items
worth to note that the maximum callstack size is exceeded for the first test case (spread operator) with n = 1 million
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Browser:
Firefox 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
for loop push
3K/s
Array(n).fill(undefined)
2K/s
Array.from
1K/s
[...Array(n).keys()].map(k => undefined)
621/s
Array.apply(null, { length: 4 })
395/s
View exact numbers
Test name
Executions per second
✓
for loop push
2,704 Ops/sec
Array(n).fill(undefined)
1,968 Ops/sec
Array.from
1,068 Ops/sec
[...Array(n).keys()].map(k => undefined)
621 Ops/sec
Array.apply(null, { length: 4 })
395 Ops/sec
Script Preparation code:
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); }