Set performance (v5)

Revision 5 of this benchmark created on


Setup

const list = new Set(Array.from({ length: 10000 }, (_, val) => val + 1))
const target = 9112

function forOf(list, target) {
	for (const val of list) {
		if (val === target) {
			return val
		}
	}
}

function forEach(list, target) {
	list.forEach((val) => {
		if (val === target) {
			return val
		}
	})
}

function forValues(list, target) {
	for (let it = list.values(), val = null; val = it.next().value;) {
		if (val === target) {
			return val
		}
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
for-of
forOf(list, target)
ready
for-of array
forOf(Array.from(list), target)
ready
forEach
forEach(list, target)
ready
forValues
forValues(list, target)
ready

Revisions

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