Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
arr.include vs binary search on sorted array vs Map.has() vs Set.has() vs Object[]
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 17
Operating system:
iOS 17.4.1
Device Platform:
Mobile
Date tested:
2 years ago
Set.has()
25.5M/s
Map.has()
25.4M/s
Obj[]
23.5M/s
binary search
12.9M/s
Includes
393K/s
View exact numbers
Test name
Executions per second
✓
Set.has()
25,519,880 Ops/sec
Map.has()
25,416,666 Ops/sec
Obj[]
23,546,096 Ops/sec
binary search
12,948,583 Ops/sec
Includes
393,039 Ops/sec
Script Preparation code:
var arr = [] var map = new Map() var set = new Set() var obj = {} for (var i = 0; i < 2000; i++) { arr.push(Math.random()) map.set(i, true) set.add(i) obj[i] = true } arr = arr.sort() function binaryIndexOf(searchElement) { var minIndex = 0 var maxIndex = this.length - 1 var currentIndex var currentElement while (minIndex <= maxIndex) { currentIndex = (minIndex + maxIndex) >>> 1 currentElement = this[currentIndex] if (currentElement < searchElement) { minIndex = currentIndex + 1 } else if (currentElement > searchElement) { maxIndex = currentIndex - 1 } else { return currentIndex } } return -1 }
Tests:
Includes
arr.includes(5)
binary search
binaryIndexOf.call(arr, 5)
Map.has()
map.has(5)
Set.has()
set.has(5)
Obj[]
obj[5]