JavaScript find vs for...of

Benchmark created on


Setup

const data = Array.from({length: 10 }).map((_, index) => index);
const getValue = () => Math.floor(Math.random() * data.length);

Test runner

Ready to run.

Testing in
TestOps/sec
Using find
for (var i = 0; i < 100000; ++i) {
	const value = getValue();
	data.find(item => item === value);
}
ready
Using for ... of
for (var i = 0; i < 100000; ++i) {
	const value = getValue();
	for (const item of data) {
		if (item === value) {
			break;
		}
	}
}
ready

Revisions

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