Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
.find vs while loop javascript
.find vs while loop javascript
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser:
Chrome 127
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
.find
111.5 Ops/sec
while loop
6.4 Ops/sec
Script Preparation code:
var data = [...Array(1000000).fill({ filtering: false, mapping: 42 }), ...Array(1000000).fill({ filtering: true, mapping: 42 })];
Tests:
.find
let next = data.find((e, index) => e.filtering === true); let next_index = data.indexOf(next); // console.log('next_login - ', next_login); // console.log('next_login_index - ', next_login_index); console.log('Index: ', next_index)
while loop
let loopStop = false; let i = 0; while (i < data.length && !loopStop) { i++; if (data[i] && data[i].filtering === true) { i--; loopStop = true; } } console.log('Index: ', i)