Set disjoint

Benchmark created on


Setup

const arr_i = [];
for (let i = 0; i < 1000; i++) {
	arr_i.push(Math.random());
}

const arr_j = [];
for (let j = 0; j < 1000; j++) {
	arr_j.push(Math.random());
}

const set_i = new Set(arr_i);
const set_j = new Set(arr_j);

Test runner

Ready to run.

Testing in
TestOps/sec
Array indexOf
const doesIntersect = arr_i.some(i => arr_j.indexOf(i) > -1);
ready
Array includes
const doesIntersect = arr_i.some(i => arr_j.includes(i));
ready
Set iterate
const doesIntersect = arr_i.some(i => set_j.has(i));
ready
Set disjoint
const doesIntersect = !set_j.isDisjointFrom(set_i);
ready

Revisions

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