Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Reduce vs Map + FromEntries vs for loop vs map
Original benchmark was unfairly forcing the for loop to be slower through variable declaration and destructuring.
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/137.0.0.0 Safari/537.36
Browser:
Chrome 137
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
map
11K/s
for loop
10K/s
reduce
7K/s
map + fromEntries
1K/s
View exact numbers
Test name
Executions per second
✓
map
11,448 Ops/sec
for loop
9,964 Ops/sec
reduce
7,050 Ops/sec
map + fromEntries
1,389 Ops/sec
Script Preparation code:
const data = Array.from(Array(10000).keys()); const dataObject = Object.entries(data)
Tests:
reduce
dataObject.reduce((acc, [k, v]) => { acc[k] = v.toString(); return acc; }, {});
map + fromEntries
Object.fromEntries(dataObject.map(([k, v]) => ([k, v.toString()])));
for loop
const hashLookup = {} for (let i = 0; i < dataObject.length; i++) { hashLookup[i] = dataObject[i]; }
map
const hashLookup = {}; (dataObject ?? []).map((value, index) => hashLookup[index] = value);