Script Preparation code:
x
 
function getArray(length) {
  const result = [];
  for (let i = 0; i < length; i++) {
    result.push(i + 'abc'); // In case the browser does some sort of optimization for arrays with only integers ¯\_(ツ)_/¯
  }
  return result;
}
function getRandomTargetElement(arrayLength) {
  const index = Math.floor(Math.random() * arrayLength);
  return index + 'abc';
}
array_small = getArray(20);
set_small = new Set(array_small);
Tests:
  • Array.includes, 20 elements

     
    array_small.includes(getRandomTargetElement(20));
  • Set.has, 20 elements

     
    set_small.has(getRandomTargetElement(20))
  • Array to Set + Set.has x 1000, 20 elements

     
    const set = new Set(array_small);
    for (let i = 0; i < 1000; i++) {
      const target = getRandomTargetElement(20);
      set.has(target)
    }
  • Array.includes x 1000, 20 elements

     
    for (let i = 0; i < 1000; i++) {
      const target = getRandomTargetElement(20);
      array_small.includes(target)
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Array.includes, 20 elements
    Set.has, 20 elements
    Array to Set + Set.has x 1000, 20 elements
    Array.includes x 1000, 20 elements

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Array.includes, 20 elements 18464856.0 Ops/sec
Set.has, 20 elements 35651828.0 Ops/sec
Array to Set + Set.has x 1000, 20 elements 41121.6 Ops/sec
Array.includes x 1000, 20 elements 20633.7 Ops/sec