small Set versus Array iteration

Benchmark created on


Setup

const objectsArray = Array.from({length: 25}).map((_, i) => ({ name: `Hello${i}`, i }))

const objectsArrayWithRepeats = objectsArray.flatMap((object, i) => {
	if (i % 3 === 0) {
		return [object]
	}
	else if (i % 3 === 1) {
		return [object, object]
	}
	return [object, object, object]
})

const objectsSet = new Set(objectsArray)

Test runner

Ready to run.

Testing in
TestOps/sec
Array with repeats
for (let i = 0; i < objectsArrayWithRepeats.length; i++) {
	console.log(objectsArrayWithRepeats[i]);
}
ready
Set
for (const object of objectsSet) {
	console.log(object);
}
ready

Revisions

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