Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce vs loop filtering performance vs flat.map
(version: 1)
https://stackoverflow.com/a/77247681
Comparing performance of:
flatMap vs reduce with push vs loop with push vs map flat()
Created:
5 months 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); }
map flat()
arr.flat().map((o) => o.assigned ? [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
map flat()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
flatMap
5682.7 Ops/sec
reduce with push
20422.9 Ops/sec
loop with push
33513.4 Ops/sec
map flat()
5563.7 Ops/sec
Related benchmarks:
flatMap vs reduce vs filter.map
flatMap vs reduce vs filter.map v2
flatMap vs reduce filtering performance
flatMap vs reduce vs loop filtering performance
flatMap vs reduce vs loop filtering performance vs filter
flatMap vs reduce vs loop filtering vs filter/map performance
Flat map + filter vs. Reduce
flatMap vs reduce vs loop performance (version: 1)
flatMap vs reduce with push vs filter x
Comments
Confirm delete:
Do you really want to delete benchmark?