Elastic index fast lookup

Benchmark created on


Setup

var arr = [];
var i = 0;

while (i <= 1E5) arr[i] = i++;

Test runner

Ready to run.

Testing in
TestOps/sec
Array.prototype.findIndex
const index = arr.findIndex(item => item === 1E5);
ready
For loop
var index = -1
for(var i = 0; i < arr.length; i++) {
    if(arr[i] === 1E5) {
        index = i;
        break;
    }
}
ready
While loop
let index = -1;
let i = 0
  const len = arr.length;
  while (++i < len) {
      if (arr[i] === 1E5) {
          index = i
          break;
      }
  }
ready

Revisions

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