Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
forEach vs reduce with group by
(version: 1)
Comparing performance of:
forEach vs reduce
Created:
13 days ago
by:
Guest
Go to the latest result
Script Preparation code:
var keyGen = () => Math.random().toString(36).substring(2, 3); var a = Array.from({length:100},()=>{ return { key: keyGen(), val: Math.random() } }); var b = {};
Tests:
forEach
a.forEach(e=>{ let t = b[e.key] || 0; b[e.key] = t + e.val; });
reduce
b = a.reduce((a,c)=> { let t = a[c.key] || 0; a[c.key] = t + c.val; return a; },{})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
forEach
reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
13 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:153.0) Gecko/20100101 Firefox/153.0
Browser/OS:
Firefox 153 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
forEach
488K/s
reduce
283K/s
View exact numbers
Test name
Executions per second
✓
forEach
487,878 Ops/sec
reduce
283,367 Ops/sec
Related benchmarks
forEach vs reduce
Object.fromEntries vs reduce vs for
Object.fromEntries vs reduce vs Map vs Object.assign vs forEach
forEach vs reduce vs whatever
Comments
Confirm delete:
Do you really want to delete benchmark?