Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set constructor from array.map vs array.forEach(.add)
(version: 1)
Comparing performance of:
new Set vs .add
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
let sourceArray = [] for(let i=1; i<1000000; i++) { sourceArray.push(i) }
Tests:
new Set
const setObject = new Set(sourceArray.map(x => x))
.add
const setObject = new Set() sourceArray.forEach(x => setObject.add(x))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new Set
.add
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new Set
29.9 Ops/sec
.add
30.5 Ops/sec
Related benchmarks:
set.add vs array.push
Array.from vs spread for converting set to array
recreate array vs set 2
Array.from vs Spread vs SetArray
set.add vs array.push Fabien2
set + array.from + map vs map + set
map.set vs array.push
Set vs Object add
Set from array vs .add
Comments
Confirm delete:
Do you really want to delete benchmark?