array find vs set has

Benchmark created on


Description

which works best for checking if an object with a particular id has been received before?

Setup

const itemsArray = [];
const itemsSet = new Set();
for (let i = 0; i < 5000; i++) {
	itemsArray.push({ id: i })
	itemsSet.add(i)
}

Test runner

Ready to run.

Testing in
TestOps/sec
Array Find
itemsArray.find(item => item.id === 4999)
ready
Set has
itemsSet.has(4999)
ready

Revisions

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