Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Chrome 102
Linux
Desktop
2 years ago
Test name Executions per second
Javascript Set intersection 0.0 Ops/sec
Lodash intersection 317247.6 Ops/sec
Javascript Array intersection 103712.8 Ops/sec
HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var first = [...Array(100)].map(it => ~~(Math.random() * 1000));
var second = [...Array(20)].map(it => ~~(Math.random() * 1000));
Tests:
  • Javascript Set intersection

    x
     
    const firstSet = new Set(first);
    const secondSet = new Set(second);
    firstSet.filter(item => secondSet.has(item));
  • Lodash intersection

     
    _.intersection(first, second)
  • Javascript Array intersection

     
    first.filter(it => second.includes(it))