Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Object vs Map vs Array (Iteration)
(version: 1)
Compare the speed to retrieve a value from three data structures that can be used for boolean referencing; i.e. for mapping enabled settings.
Comparing performance of:
Set vs Object vs Map vs Array
Created:
8 months ago
by:
Guest
Go to the latest result
Script Preparation code:
const array = Array.from({ length: 10000 }, (_, idx) => idx); const set = new Set(array); const object = Object.fromEntries(array.map((x) => [x, true])); const map = new Map(Object.entries(object));
Tests:
Set
let sum = 0; set.forEach((v) => { sum += v; });
Object
let sum = 0; for(const k in object){ const v = object[k] sum += v; }
Map
let sum = 0; map.forEach((v) => { sum += v; });
Array
let sum = 0; array.forEach((v) => { sum += v; });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Set
Object
Map
Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Array
54K/s
Set
19K/s
Map
16K/s
Object
5K/s
View exact numbers
Test name
Executions per second
✓
Array
54,224 Ops/sec
Set
18,723 Ops/sec
Map
16,148 Ops/sec
Object
5,440 Ops/sec
Related benchmarks
map over Object (or Record in TS) vs Map
map vs object test here
map over Object (or Record in TS) vs Map updated
Comments
Confirm delete:
Do you really want to delete benchmark?