Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Populating a Set
(version: 1)
Comparing performance of:
Map vs Loop
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const make = (length) => ({ id: length, items: Array.from({ length }, () => make(length / 2)) }) const data = make(20)
Tests:
Map
const ids = Array.from(new Set( data.items.map( i => i.items.map( ii => ii.items ) ).flat(2) .filter(item => item.id % 2 === 0) .map(item => item.id.toString()) ))
Loop
const items = new Set() for (const i of data.items) for (const ii of i.items) for (const item of ii.items) if (item.id % 2 === 0) items.add(item.id.toString()) const ids = Array.from(items)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Map
Loop
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Map
55144.3 Ops/sec
Loop
143741.3 Ops/sec
Related benchmarks:
TestPerf
TestsPerf
TestsPerf2
TestsPerf21
is find arrays cached
for vs. for-of vs. reduce (array to ID-keyed object)
Array merge
Test spreads1
Array.find vs Map
Comments
Confirm delete:
Do you really want to delete benchmark?