Set.has( object ) vs Array.includes( object )

Benchmark created on


Setup

const arr = [...Array(28)].map((_, i) => ({v: i}))
const set = new Set(arr)

const [ one, two, three, four, five ] =
	// reverse so objects are from end of array
	arr.reverse()

Test runner

Ready to run.

Testing in
TestOps/sec
set.has
const isIn = set.has(one) && set.has(two) && set.has(three) && set.has(four) && set.has(five);
ready
array.includes
const isIn = arr.includes(one) && arr.includes(two) && arr.includes(three) && arr.includes(four) && arr.includes(five);
ready

Revisions

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