includes vs indexOf

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
includes
const generatePseudoRandom = (from, to) => parseInt(Math.random() * to) + from;
const ids = [];
let i = 0;

while (++i < 10000) { // 10000 elements
  ids.push(generatePseudoRandom(1, 999999999));
  if (ids.includes(0)) {
    break;
  }
}
ready
indexOf
const generatePseudoRandom = (from, to) => parseInt(Math.random() * to) + from;
const ids = [];
let i = 0;

while (++i < 10000) { // 10000 elements
  ids.push(generatePseudoRandom(1, 999999999));
  if (ids.indexOf(0) > -1) {
    break;
  }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.