test

Benchmark publishedon

Description

const arr = new Array(1000000) for(let i = 0; i < arr.length; i++) { arr[i] = i + 1; }

Test Runner

Initializing...

Testing in
Test CaseOps/sec
linear
function numberSerch(arr, el) {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === el) {
      return i;
    }
  }
  return -1;
}
const el = Math.floor(Math.random() * arr.length)
numberSerch(arr, el)

ready
bin-search
function searchElement(arr, el) {
  let left = -1;
  let right = arr.length;

  while (right - left > 1) {
    const mid = Math.floor((left + right) / 2);
    if (arr[mid] === el) {
      return mid;
    }

    if (arr[mid] > el) {
      right = mid;
    } else {
      left = mid;
    }
  }

  return -1;
}
const el = Math.floor(Math.random() * arr.length)
numberSerch(arr, el)


ready

Revisions

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

Revision 1
publishedon