Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
MapBy reduce vs foreach
(version: 1)
Comparing performance of:
reduce vs foreach
Created:
one year ago
by:
Guest
Go to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const objects = []; for (let i = 1; i <= count; i++) { const obj = { id: crypto.randomUUID(), name: `object-${i}` }; objects.push(obj); }
Tests:
reduce
const mapBy = (array, key) => { return array.reduce((acc, item) => { acc[item[key]] = item; return acc; }, {}); } mapBy(objects);
foreach
const mapBy = (array, key) => { const map = {} return array.forEach((item) => { map[item[key]] = item; }); return map } mapBy(objects);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
reduce
foreach
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
foreach
61.7M/s
reduce
58.2M/s
View exact numbers
Test name
Executions per second
✓
foreach
61,731,360 Ops/sec
reduce
58,235,840 Ops/sec
Related benchmarks
Reduce vs Map+FromEntries vs for loop
Reduce vs Map+FromEntries vs for loop vs forEach
Reduce Object.assign vs spread
Object.fromEntries vs reduce vs property assignment
Object.fromEntries vs reduce vs property assignment vs Map
Object.fromEntries vs reduce vs Map vs for of vs forEach
Object.fromEntries(Array.map) vs Array.reduce (with different methods)
reduce object vs object.fromentries (1K records)
Comments
Confirm delete:
Do you really want to delete benchmark?