Array vs Set difference

Benchmark created on


Setup

let a = [1,2,3,4,5,6,7,8,9,10];
let b = [4,3,2,9,10,7,8,5,6];

Test runner

Ready to run.

Testing in
TestOps/sec
Set difference
let sa = new Set(a);
let sb = new Set(b);

Array.from(sa).filter(x => !sb.has(x))
ready
Array difference
a.filter(x => !b.includes(x));
ready
Array & Set difference
let sb = new Set(b);

a.filter(x => !sb.has(x))
ready
Set forEach difference
let sa = new Set(a);
let sb = new Set(b);

let c = new Set();
sa.forEach((x) => {
  if (!sb.has(x)) c.add(x);
});
ready

Revisions

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