some vs. early exit loop

Benchmark created on


Setup

let arr = []
for (let i = 0; i < 30000; i++) {
	arr[i] = i;
}
arr[15000]='apple';

Test runner

Ready to run.

Testing in
TestOps/sec
.some
arr.some((item) => item === 'apple')
ready
Early exit
for (let i = 0; i < arr.length; i++) {
	if (arr[i] === 'apple')
		break;
}
ready

Revisions

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