HashTable vs Includes

JavaScript performance comparison

Test case created by sakalx

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
includes
const arr = [];

for (let i = 0; i < 500; i++) {
	arr[i] = Math.random() * 1000 | 0
}

function doTheyAddTo(a, k){
    for (const n of a) {
        if (a.includes(k-=n))  {
            return true
            }
        }
        return false
    }

doTheyAddTo(arr, -1)
pending…
hashTable
const arr = [];

for (let i = 0; i < 500; i++) {
	arr[i] = Math.random() * 1000 | 0
}


function Problem01(arr, sum) {
  const hashTable = {};

  for (let num of arr) {

    if (!hashTable[num]) hashTable[sum - num] = num;
    else return true;
  }

  return false
}

Problem01(arr, -1)
pending…

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

Compare results of other browsers

0 Comments