Tests:
  • find

    x
     
    const arr = Array.from({ length: 20000 }, (_, i) => ({ property: i }))
    const elementToFind = 15000;
    const element = arr.find((el) => el.property === elementToFind);
  • For-loop

     
    const arr = Array.from({ length: 20000 }, (_, i) => ({ property: i }))
    const elementToFind = 15000;
    let element = undefined;
    for (let i = 0; i < arr.length; i++) {
        if (arr[i].property === elementToFind) {
          element = arr[i];
          break;
        }
    }
  • while

     
    const arr = Array.from({ length: 20000 }, (_, i) => ({ property: i }))
    const elementToFind = 15000;
    let element = undefined;
    let i = 0;
    while(element === undefined) {
      if(arr[i].property === elementToFind) {
        element = elementToFind;
      }
      i++;
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    find
    For-loop
    while

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Chrome 109 on Windows
View result in a separate tab
Test name Executions per second
find 598.5 Ops/sec
For-loop 634.3 Ops/sec
while 255.8 Ops/sec