Diffing 2 arrays using sets

Benchmark created on


Setup

const ARR_SIZE = 100000;
const randInt = (min, max) => Math.random() * (max - min) + min;

const array1 = new Array(ARR_SIZE).fill(0).map(_ => randInt(0, 10000));

const array2 = new Array(ARR_SIZE).fill(0).map(_ => randInt(0, 10000));

Test runner

Ready to run.

Testing in
TestOps/sec
Using 1 set
const set = new Set(array1);
const diff = array2.filter(i => !set.has(i));
ready
Using 2 sets and Set.difference
const set1 = new Set(array1);
const set2 = new Set(array2);

const diff = set2.difference(set1);
ready

Revisions

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