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
Jump 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
Test name
Executions per second
reduce
58235840.0 Ops/sec
foreach
61731360.0 Ops/sec
Related benchmarks:
Reduce vs Map+FromEntries vs for loop
Object vs Map creation (forEach, reduce)
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?