for loop with break vs array.some

Benchmark created on


Setup

let array = [];
let i = 1;

while (i < 100000) {
    array.push(Math.random()*10000);
    i++;
}

Test runner

Ready to run.

Testing in
TestOps/sec
For loop with break
let flag = false;

for (let i = 0; i < array.length; i++) {
	if (array[i] > 10000/2) {
        flag = true;
        break;
    }
}

console.log(flag);
ready
Array.some
const flag = array.some((item) => {
    if (item > 10000/2) {
        return true;
    }
    
    return false
});

console.log(flag);
ready

Revisions

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