Array.includes and find methods vs Set.has

JavaScript performance comparison

Test case created by Artur

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  size = 100;
  next = 0;
  arr = (new Array(size)).join(' ').split(' ')
    .map((a, i) => ({ v: i, i }));
  set = new Set(arr);
  map = new Map([...arr.map(v => [v, v])]);
  
  next = 0;
  rand = () => arr[Math.floor(Math.random() * size)];
  
  
  

};
</script>

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
Set.has
val = rand();
set.has(val);
pending…
Map.has
val = rand();
map.has(val);
pending…
Array.includes
val = rand();
arr.includes(val);
pending…
Array.indexOf
val = rand();
arr.indexOf(val);
pending…
Array.find
val = rand();
arr.find(v => v === val);
pending…
Array.findIndex
val = rand();
arr.findIndex(v => v === val);
pending…

Revisions

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

0 Comments