Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce vs loop filtering performance vs filter/map
(version: 1)
https://stackoverflow.com/a/77247681
Comparing performance of:
flatMap vs reduce with push vs loop with push vs filter/map
Created:
one month 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); }
filter/map
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
filter/map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.5 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
flatMap
3865.4 Ops/sec
reduce with push
10731.1 Ops/sec
loop with push
7453.1 Ops/sec
filter/map
7689.6 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 with push vs filter x
flatMap vs reduce vs loop filtering performance vs flat.map
Comments
Confirm delete:
Do you really want to delete benchmark?