ArrayDiff

Benchmark created on


Setup

const floodFill = (n = 40) => 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
function *setMinus(A, B) {
      const setA = new Set(A);
      const setB = new Set(B);

      for (const v of setB.values()) {
        if (!setA.delete(v)) {
            yield v;
        }
      }

      for (const v of setA.values()) {
        yield v;
      }
    }

console.log(Array.from(setMinus(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.