Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set vs Object vs Map vs array but with strings
(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
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:
8 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
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Set
234.2M/s
Map
228.9M/s
Object
177.3M/s
Array
52K/s
View exact numbers
Test name
Executions per second
✓
Set
234,187,712 Ops/sec
Map
228,874,096 Ops/sec
Object
177,250,592 Ops/sec
Array
51,863 Ops/sec
Related benchmarks
Object.hasOwnProperty vs Object in vs Object[] vs Array.indexOf vs Array.find vs Map.has
Array.includes vs Set.has vas Map.has big
new Map vs set array to map
set.has vs. array.includes vs plain object
Set has vs object key - small object, no caching
Set vs Object vs Map vs array
Set vs Object vs Map vs Array (Iteration)
Comments
Confirm delete:
Do you really want to delete benchmark?