hasOrIncludes

Benchmark created by Sushant Bhatia on


Setup

var arr1 = [];
  var  i;
  for (i = 0; i < 10;i++) {
    arr1[i] = Math.floor(Math.random() * 100);
  }
  var set1 = new Set(arr1);
  
  var arr2 = [];
  for (i = 0; i < 100;i++) {
    arr2[i] = Math.floor(Math.random() * 100);
  }
  var set2 = new Set(arr2);
  
  
  var arr3 = [];
  for (i = 0; i < 1000;i++) {
    arr3[i] = Math.floor((Math.random() * 100));
  }
  var set3 = new Set(arr3);

Test runner

Ready to run.

Testing in
TestOps/sec
small array
var rand = Math.floor(Math.random() * 100)

arr1.includes(rand);
ready
small set
var rand = Math.floor(Math.random() * 100)

set1.has(rand)
ready
medium array
var rand = Math.floor(Math.random() * 100)

arr2.includes(rand);
ready
medium set
var rand = Math.floor(Math.random() * 100)

set2.has(rand);
ready
large array
var rand = Math.floor(Math.random() * 100)

arr3.includes(rand);
ready
large set
var rand = Math.floor(Math.random() * 100)

set3.has(rand);
ready

Revisions

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

  • Revision 1: published by Sushant Bhatia on