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
Go 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:
10 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
.add
31/s
new Set
30/s
View exact numbers
Test name
Executions per second
✓
.add
31 Ops/sec
new Set
30 Ops/sec
Related benchmarks
set.add vs array.push
Array.from vs spread for converting set to array
map.set vs array.push
Set vs Object add
Set from array vs .add
Comments
Confirm delete:
Do you really want to delete benchmark?