Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array ops - for-each vs double map-filter
(version: 1)
Comparing performance of:
For-Each vs map + filter twice
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ async function globalMeasureThatScriptPrepareFunction() {}
Tests:
For-Each
const exampleObjects = Array.from(Array(1000)).map((_, i) => { const randomId = Math.round(Math.random() * 100); const otherRandomId = Math.round(Math.random() * 100); return { objectId: i % 3 === 0 ? undefined : randomId.toString(), clientObjectId: i % 4 === 0 ? undefined : otherRandomId.toString(), } }); const objectIds = new Set(exampleObjects.map(i => i.objectId).filter(i => i !== undefined)); const clientObjectIds = new Set(exampleObjects.map(i => i.clientObjectId).filter(i => i !== undefined));
map + filter twice
const exampleObjects = Array.from(Array(1000)).map((_, i) => { const randomId = Math.round(Math.random() * 100); const otherRandomId = Math.round(Math.random() * 100); return { objectId: i % 3 === 0 ? undefined : randomId.toString(), clientObjectId: i % 4 === 0 ? undefined : otherRandomId.toString(), } }); const objectIds = new Set(); const clientObjectIds = new Set(); for (const i of exampleObjects) { if (i.objectId) objectIds.add(i.objectId); if (i.clientObjectId) clientObjectIds.add(i.clientObjectId); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
For-Each
map + filter twice
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
For-Each
16738.5 Ops/sec
map + filter twice
20723.4 Ops/sec
Related benchmarks:
Array to object benchmark
Value existance check in object, array, map, set
forEach vs mapfilter vs transduce
set + array.from + map vs map + set
map vs obj vs array
map vs obj vs array 2
Performance of JavaScript .forEach, for in
Map vs Find to change one el in array of objects
Map.values().toArray() vs Array.from(Map.values()) vs [...Map.values()]
Comments
Confirm delete:
Do you really want to delete benchmark?