Script Preparation code:
x
 
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>

Previous results

Experimental features:

  • Test case name Result
    includes
    binary
    indexof

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0
Firefox 102 on Windows
View result in a separate tab
Test name Executions per second
includes 21670970.0 Ops/sec
binary 24864620.0 Ops/sec
indexof 21294478.0 Ops/sec