Script Preparation code:
x
 
var arr = [];
for (let i = 0; i < 100; i++) {
    arr.push(i);
}
function forLoop(array, item) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] === item) {
          return i;
        }
    }
    return -1;
}
function whileLoop(array, item) {
    var i = 0;
    while (i < array.length) {
        if (array[i] === item) {
            return i;
        }
        i += 1;
    }
    return -1;
}
function index(array, item) {
    return array.indexOf(item);
}
function sort(array, item) {
    let arr2 = arr.sort();
    return arr2[0];
}
Tests:
  • 431

     
    index(arr, 101)
  • 123

     
    sort(arr, 101)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    431
    123

    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; rv:120.0) Gecko/20100101 Firefox/120.0
Firefox 120 on Windows
View result in a separate tab
Test name Executions per second
431 11468794.0 Ops/sec
123 1013625.0 Ops/sec