Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Array vs Object for unique list. Then map
(version: 0)
Comparing performance of:
Unique Array vs Set vs Object
Created:
5 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var a = Array(1000).fill(null).map((a, b) => b);
Tests:
Unique Array
var b = []; a.forEach(x => { if (!b.includes(x)) b.push(x); }); b.map(x => x);
Set
var c = new Set(); a.forEach(x => c.add(x)); var d = Array.from(c); d.map(x => x);
Object
var e = {}; a.forEach(x => { if (!e[x]) e[x] = x }); Object.keys(e).map(x => e[x]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Unique Array
Set
Object
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/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Unique Array
15099.3 Ops/sec
Set
33444.6 Ops/sec
Object
32917.4 Ops/sec
Related benchmarks:
Array from() vs Map.keys()
Array from() vs Map.keys() vs Map.values() vs spread
Array from() vs Map.keys() vs Map.values() vs spread (fixed)
Array.from() vs new Array() performance...
fill array with value: map(callback) vs fill(value) 2
Comments
Confirm delete:
Do you really want to delete benchmark?