Intersection Best Practices

Benchmark created on


Setup

const size = 1000;
const arr1 = Array.from({length: size}, () => Math.random() * Math.pow(10, Math.floor(Math.random() * 10)));
const arr2 = Array.from({length: size}, () => Math.random() * Math.pow(10, Math.floor(Math.random() * 10)));

Teardown

arr1.length = 0;
arr2.length = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
Filter

arr1.filter(x => arr2.includes(x));
ready
Set
const set2 = new Set(arr2);
arr1.filter(x => set2.has(x));
ready

Revisions

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