Script Preparation code:
x
 
var array = [];
for (var i=0; i<300; ++i) {
    array.push('00' + i);
}
function hasWithIndexOf(needle) {
    return array.indexOf(needle) !== -1;
}
var map = new Map();
array.forEach(item => map.set(item, true));
function hasWithMap(needle) {
    return map.get(needle);
}
Tests:
  • indexOf

     
    for (var i=0; i<100; ++i) {
        hasWithIndexOf('404');
    }
  • map

     
    for (var i=0; i<100; ++i) {
        hasWithMap('404');
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    indexOf
    map

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 months ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 YaBrowser/24.7.0.0 Safari/537.36
Yandex Browser 24 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
indexOf 29249.9 Ops/sec
map 124795.1 Ops/sec