includes vs indexOf vs has (v2)

Revision 2 of this benchmark created on


Setup

const foo = [1, 2, 3, 4, 5, 6];
const bar = new Set([1, 2, 3, 4, 5, 6]);
const fooBig = new Array(10000);
const barBig = new Set();
for(let i=1; i<=10000; i++) {
  fooBig[i-1] = i;
  barBig.add(i);
}

Test runner

Ready to run.

Testing in
TestOps/sec
asArrIncludes
const asArrIncludes = foo.includes(6);
ready
asArrIndex
const asArrIndex = foo.indexOf(6) >= 0;
ready
asSet
const asSet = bar.has(6);
ready
asIncludesBig
const asIncludesBig = fooBig.includes(10000);
ready
asIndexOfBig
const asIndexOfBig = fooBig.indexOf(10000) >= 0;
ready
asSetBig
const asSetBig = barBig.has(10000);
ready
toSet
const asIndexOfBig = (new Set(foo)).has(10000)
ready
toSetBig
const asIndexOfBig = (new Set(fooBig)).has(10000)
ready

Revisions

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