Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Include vs Binary search in sorted array vs Map.has() vs Object[]
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser:
Chrome 135
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Map.has()
232.4M/s
Obj[]
209.0M/s
binary
83.2M/s
Includes
3.3M/s
View exact numbers
Test name
Executions per second
✓
Map.has()
232,427,344 Ops/sec
Obj[]
209,039,776 Ops/sec
binary
83,162,464 Ops/sec
Includes
3,253,604 Ops/sec
Script Preparation code:
var array = []; var map = new Map(); var obj = {}; for (var i = 0; i < 2000; i++){ array.push(Math.random()); map.set(i,true); obj[i]=true; } var sorted = array.sort() function binaryIndexOf(searchElement) { var minIndex = 0; var maxIndex = this.length - 1; var currentIndex; var currentElement; while (minIndex <= maxIndex) { currentIndex = (minIndex + maxIndex) / 2 | 0; currentElement = this[currentIndex]; if (currentElement < searchElement) { minIndex = currentIndex + 1; } else if (currentElement > searchElement) { maxIndex = currentIndex - 1; } else { return currentIndex; } } return -1; }
Tests:
Includes
sorted.includes(5)
binary
binaryIndexOf.call(sorted, 5)
Map.has()
map.has(5);
Obj[]
obj[5]