Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set has vs object key - small object, no caching
(version: 1)
performance comparison of looking up a value from a set
Comparing performance of:
Includes vs Object[key] vs Set.has
Created:
one year ago
by:
Registered User
Go to the latest result
Script Preparation code:
var obj = { '.': true, ' ': true, ',': true, ';': true, }; var array = Object.keys(obj); var set = new Set(array); function getKey() { return array[Math.floor(Math.random() * array.length)]; } function getNonKey() { return Math.random() > 0.5 ? '!' : '?'; }
Tests:
Includes
array.includes(getKey()) && array.includes(getNonKey())
Object[key]
obj[getKey()] && obj[getNonKey()]
Set.has
set.has(getKey()) && set.has(getNonKey())
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Includes
Object[key]
Set.has
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Set.has
20.0M/s
Includes
15.9M/s
Object[key]
14.9M/s
View exact numbers
Test name
Executions per second
✓
Set.has
19,964,588 Ops/sec
Includes
15,876,717 Ops/sec
Object[key]
14,940,740 Ops/sec
Related benchmarks
Map vs Object (large number of keys)
Map vs Object (3)
String in Array: Set vs Object lookup vs IndexOf vs includes vs findIndex vs find v2
Map vs Object (real-world) Performance (string keys)
Set has vs object key - small object
Comments
Confirm delete:
Do you really want to delete benchmark?