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:
x
 
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
var arr = [];
var arr2 = [];
for(var i = 0; i < 51; i++){
    arr.push(getRandomInt(100));
    arr2.push(getRandomInt(100));
}
Tests:
  • lodash

     
    _.intersection(arr,arr2);
  • sort

     
    var getArrayIntersection = (a, b) => {
      var setA = new Set(a),
        setB = new Set(b);
      var comparator = {
        array: setA,
        set: setB,
      };
      if (setA.size > setB.size) {
        comparator.array = setB;
        comparator.set = setA;
      }
      const intersection = [...comparator.array].filter((el) =>
        comparator.set.has(el),
      );
      return intersection;
    };
                                                        
                                                        getArrayIntersection(arr, arr2);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    lodash
    sort

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Chrome 104 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
lodash 400602.2 Ops/sec
sort 434852.7 Ops/sec