Script Preparation code:
x
 
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]
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Includes
    binary
    Map.has()
    Obj[]

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 days ago)
Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Chrome 132 on Chrome OS 14541.0.0
View result in a separate tab
Test name Executions per second
Includes 491243.8 Ops/sec
binary 19182264.0 Ops/sec
Map.has() 70701072.0 Ops/sec
Obj[] 71325104.0 Ops/sec