Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Object vs Map vs array
(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:
one year 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
set.has(0); set.has(42); set.has(69); set.has(9999); set.has(520); set.has(1314); set.has(168); set.has(19); set.has(4); set.has(10000);
Object
0 in object; 42 in object; 69 in object; 9999 in object; 520 in object; 1314 in object; 168 in object; 19 in object; 4 in object; 10000 in object;
Map
map.has(0); map.has(42); map.has(69); map.has(9999); map.has(520); map.has(1314); map.has(168); map.has(19); map.has(4); map.has(10000);
Array
array.includes(0); array.includes(42); array.includes(69); array.includes(9999); array.includes(520); array.includes(1314); array.includes(168); array.includes(19); array.includes(4); array.includes(10000);
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:
one month ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:149.0) Gecko/20100101 Firefox/149.0
Browser/OS:
Firefox 149 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
208454016.0 Ops/sec
Object
1997188480.0 Ops/sec
Map
209962624.0 Ops/sec
Array
45726.4 Ops/sec
Related benchmarks:
Map.get vs Object[i] vs Map.has
Compare Nulling, undefining and deleting of Javascript Object vs Map
contains misses: Map vs Set vs Array vs Symbol vs UID
Map has vs Object []
Map vs Object (2)
Map vs Object (3)
Object.values vs for in loop vs for loop v3
indexOf vs map.get vs obj[key]
Object key access vs array find vs map
Comments
Confirm delete:
Do you really want to delete benchmark?