array vs set

Benchmark created on


Setup

const rand = (size) => [...Array(size)].map(() => Math.floor(Math.random() * size));

const a1 = rand(1000000);
const a2 = rand(1000000);

Test runner

Ready to run.

Testing in
TestOps/sec
array
const res = a1.filter((el) => a2.includes(el));
ready
set
const a2Set = new Set(a2);

const res = a1.filter((el) => a2Set.has(el));
ready

Revisions

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