ArrayDiff (v2)

Revision 2 of this benchmark created on


Setup

const floodFill = (n = 1000) => Array.from({length: n}, () => Math.floor(Math.random() * n));


const a = floodFill();
const b = floodFill();

Test runner

Ready to run.

Testing in
TestOps/sec
Test A
const arrayDiff = (A, B) =>  A.filter(function(x) {
  return B.indexOf(x) < 0;
});

console.log(Array.from(arrayDiff(a, b)));
ready
Test B
const arrayDiff = (a, b) => {
  return a.map((x) => (!b.includes(x) ? x : null)).filter(Boolean);
};

console.log(Array.from(arrayDiff(a, b)));
ready

Revisions

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