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:
5 months ago
by:
Guest
Jump 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:
5 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
Test name
Executions per second
Set
18723.1 Ops/sec
Object
5439.7 Ops/sec
Map
16148.5 Ops/sec
Array
54223.5 Ops/sec
Related benchmarks:
Map vs Object (get) [2]
getListOfPropertyValues Comparation
Object vs Map creation (forEach, reduce, for)
set + array.from + map vs map + set
for loop: object vs map
Object.values vs for in loop vs for loop v3
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?