Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce vs loop filtering performance vs filter
(version: 0)
https://stackoverflow.com/a/77247681
Comparing performance of:
flatMap vs reduce with push vs loop with push vs Filtermap
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = Array.from({length:10000}, (v, i) => ({name: i, assigned: Math.random() < 0.5}));
Tests:
flatMap
arr.flatMap((o) => (o.assigned ? [o.name] : []));
reduce with push
arr.reduce((a, o) => (o.assigned && a.push(o.name), a), [])
loop with push
{ const a = []; for (const o of arr) if (o.assigned) a.push(o.name); }
Filtermap
arr.filter(o => o.assigned).map(o => o.name)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
flatMap
reduce with push
loop with push
Filtermap
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
flatMap
2404.1 Ops/sec
reduce with push
22659.1 Ops/sec
loop with push
30287.9 Ops/sec
Filtermap
20122.3 Ops/sec
Related benchmarks:
flatMap vs reduce filtering performance
flatMap vs reduce vs loop filtering performance
flatMap vs reduce vs loop filtering vs filter/map performance
Flat map + filter vs. Reduce
Comments
Confirm delete:
Do you really want to delete benchmark?