Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
object[]: findIndex vs for loop with more complex condition check
(version: 0)
Testing Array.prototype.findIndex vs a for loop over an array of objects
Comparing performance of:
findIndex vs for loop
Created:
4 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var length = 1e3 var arr = Array.from({length},(_,i) => ({id: i, rand: i * Math.random()})); var target = Math.floor(length * Math.random());
Tests:
findIndex
let outIdx1 = arr.findIndex((x) => x.id > target && x.rand > length/3 && Math.random() > .5 ); /*console.log('findIndex',outIdx1)*/
for loop
let outIdx2 = -1 for (let i = 0; i < arr.length; i++) { if (arr[i].id > target && arr[i].rand > length/3 && Math.random() > .5) { outIdx2 = i break } } /*console.log('for loop',outIdx2)*/
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
findIndex
for loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
findIndex vs indexOf for simple array 2
object[]: findIndex vs for loop
Object arrays: findIndex vs for loop2
Object arrays: findIndex vs for loop (length cached)
Comments
Confirm delete:
Do you really want to delete benchmark?