Symmetric Difference of an Array (v3)

Revision 3 of this benchmark created on


Setup

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

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

Test runner

Ready to run.

Testing in
TestOps/sec
Array.indexOf
const setDiff = (a, b) => a.filter((x) => b.indexOf(x) < 0);

const arraySymmetricDiff = (a, b) => {
  return [ ...setDiff(a, b), ...setDiff(b, a) ];
};

console.log(Array.from(arraySymmetricDiff(a, b)));
ready
Array.includes
const setDiff = (a, b) => a.filter((x) => !b.includes(x));

const arraySymmetricDiff = (a, b) => {
  return [ ...setDiff(a, b), ...setDiff(b, a) ];
};

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

Revisions

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