Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Search small array
(version: 0)
Comparing performance of:
includes vs binary vs indexof
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array = []; var map = new Map(); var obj = {}; for (var i = 0; i < 20; i++){ array.push(Math.floor(Math.random()*5)); 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 = sorted[currentIndex]; if (currentElement < searchElement) { minIndex = currentIndex + 1; } else if (currentElement > searchElement) { maxIndex = currentIndex - 1; } else { return currentIndex; } } return -1; }
Tests:
includes
sorted.includes(Math.floor(Math.random()*7))
binary
binaryIndexOf(Math.floor(Math.random()*7))
indexof
sorted.indexOf(Math.floor(Math.random()*7))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
includes
binary
indexof
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
Include vs Binary search in sorted array
Include vs Binary search in sorted array vs Map.has()
Include vs Binary search in sorted array vs Map.has() vs Object[]
Include vs Binary search in sorted array vs Map.has() vs Object[] (150 elements)
Comments
Confirm delete:
Do you really want to delete benchmark?