Array `includes()` vs Set `has()` (v2)

Revision 2 of this benchmark created on


Setup

const arr = [];
const set = new Set();
const values = [];
for (let i = 0; i < 5000; ++i) {
	const value = { num: i }
	arr.push(value);
	set.add(value);
	values.push(value);
}

function getRandomInt(max) {
  return Math.floor(Math.random() * max);
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array `includes()`
arr.includes(values[getRandomInt(10000)]);
ready
Set `has()`
set.has(values[getRandomInt(10000)]);
ready

Revisions

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