Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Initializing array with map function - JS version of Python list comprehension
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Spread operator
295.7 Ops/sec
Array apply
343.6 Ops/sec
Array from
298.0 Ops/sec
Array fill
668.0 Ops/sec
For loop push
548.1 Ops/sec
Script Preparation code:
var n = 100000; // 100k function filler(v, i) { return i ** 2; }
Tests:
Spread operator
[...Array(n).keys()].map(filler);
Array apply
Array.apply(null, { length: n }).map(filler);
Array from
Array.from({ length: n }, filler);
Array fill
Array(n).fill(undefined).map(filler)
For loop push
const arr = []; for (let i = 0; i < n; i++) { arr.push(filler(null, i)); }