Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
flatMap vs reduce vs loop filtering vs filter/map performance
(version: 0)
Comparing performance of:
flatMap vs reduce with push vs loop with push vs filter with a map
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); }
filter with a map
arr.filter(item => item.assigned).map(item => item.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 with a map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36
Browser/OS:
Chrome Mobile 141 on Android
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
flatMap
1306.6 Ops/sec
reduce with push
2302.3 Ops/sec
loop with push
7243.9 Ops/sec
filter with a map
1548.0 Ops/sec
Related benchmarks:
flatMap vs reduce filtering performance
flatMap vs reduce vs loop filtering performance
flatMap vs reduce vs loop filtering performance vs filter
Flat map + filter vs. Reduce
Comments
Confirm delete:
Do you really want to delete benchmark?