findIndex

Benchmark created on


Setup

const A = []
for (let i = 0; i < 10_000; i++) {
	A.push({ i })
}

function fi(a, pred) {
	return a.findIndex(pred)
}

function manual(a, pred) {
	for (let i = 0; i < a.length; i++) {
		if (pred(a[i])) return i
	}
}

function iter(a, pred) {
	for (const [i, o] of a.entries()) {
		if (pred(o)) return i
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
findIndex
fi(A, (o) => o.i === 5000)
ready
manual
manual(A, (o) => o.i === 5000)
ready
iter
iter(A, (o) => o.i === 5000)
ready

Revisions

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