Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test reduce vs flatMap
(version: 0)
Comparing performance of:
reduce vs flatMap + filter
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
window.providerMenuItems = Object.fromEntries( Array.from({ length: 1000 }).map((_, id) => [id, { id }]), ); window.subtreeDishes = new Array(1000).fill(null).map((_, index) => ({ id: index, child_ids: Array.from({ length: 10 }).map(() => Math.floor(Math.random() * 2000)), }));
Tests:
reduce
subtreeDishes.reduce((res, dish) => { dish.child_ids.forEach((childId) => { if (providerMenuItems[childId]) { res.push(providerMenuItems[childId]); } }); return res; }, []);
flatMap + filter
subtreeDishes .flatMap((dish) => dish.child_ids.map((itemId) => providerMenuItems[itemId])) .filter((val) => val != null);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
reduce
flatMap + filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
flatMap vs reduce (inner object)
flatMap vs reduce (inner object1111)
flatMap vs reduce (inner object11111)
flatMap vs reduce with push testtttteste212312
Flatmap vs reduce with objects
Comments
Confirm delete:
Do you really want to delete benchmark?