Script Preparation code:
AخA
 
var arr1 = Array(1000).fill().map(() => Math.round(Math.random() * 100));
var arr2 = Array(1000).fill().map(() => Math.round(Math.random() * 100));
Tests:
  • Test reduce

    x
     
    const fn = (arr1, arr2) => {
      return arr2.reduce((acc, item) => {
        if (arr1.includes(item) && !acc.includes(item)) {
          acc.push(item);
        }
        return acc;
      }, []);
    };
    fn(arr1, arr2)
  • Test 2

     
    const fn = (arr1, arr2) => {
      return Array.from(new Set(arr2.filter((item) => arr1.includes(item))));
    };
    fn(arr1, arr2)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Test reduce
    Test 2

    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/100.0.4896.75 Safari/537.36
Chrome 100 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Test reduce 7845.7 Ops/sec
Test 2 8703.2 Ops/sec