includes vs indexOf (v2)

Revision 2 of this benchmark created on


Description

Looks like for arrays of numbers there is no difference. Let's check how it looks like for arrays of strings.

Setup

const ids = [];
const max = 1000;
let i = 0;

Teardown

ids.length = [];
i = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
includes - string
while (++i < max) {
  ids.push((i + max).toFixed(36));
  if (ids.includes((i + max * 2).toFixed(36))) {
    break;
  }
}
ready
indexOf - string
while (++i < max) {
  ids.push((i + max).toFixed(36));
  if (ids.indexOf((i + max * 2).toFixed(36)) > -1) {
    break;
  }
}
ready

Revisions

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