Set::has vs Array::includes

Benchmark created on


Setup

const haystackArray = Array.from({ length: 500 }).map((_, idx) => `item-${idx}`);
const haystackSet = new Set(haystackArray);

const assert = (val) => {
	if (!val) throw new Error("assertion violated");
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array::includes
assert(haystackArray.includes('item-250'));
assert(!haystackArray.includes('not-present'));
ready
Set::has
assert(haystackSet.has('item-250'));
assert(!haystackSet.has('not-present'));
ready

Revisions

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