some vs set

Benchmark created on


Description

determine if two arrays have intersecting values

Setup

const a = [1,2,3,4,5,6,7,8,9,10,'foo','bar','baz']
const b = [10,20,30,40,50,60,70,80,90,100,'foo1','bar2','baz3']
const c = [11,21,31,41,51,61,71,81,91,101,'foo2','bar3','baz']

Test runner

Ready to run.

Testing in
TestOps/sec
some
const doesIntersect = a.some(inner => c.includes(inner));
const doesNotIntersect = a.some(inner => b.includes(inner));

ready
set
const doesIntersect = new Set([...a, ...c]).size < (a.length + c.length)
const doesNotIntersect = new Set([...a, ...b]).size < (a.length + b.length)
ready
set::intersection
const doesIntersect = new Set(a).intersection(new Set(c)).size > 0
const doesNotIntersect = new Set(a).intersection(new Set(b)).size > 0
ready

Revisions

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