set difference

Benchmark created on


Setup

const randomString = () => Math.random().toString(36).slice(2, 7)

const getAllBuckets = () => {
    return new Array(2e5).fill(1).map((b) => randomString())
}

Test runner

Ready to run.

Testing in
TestOps/sec
[big] loop thru all
const all = getAllBuckets()
const excludedLookup = new Set(all)
const included = []

for (const b of all) {
	if (!excludedLookup.has(b)) {
		included.push(b)
	}
}

ready
[big] loop through excluded
const all = getAllBuckets()
const allSet = new Set(all)

for (const b of all) {
	allSet.delete(b)
}

const done = Array.from(allSet)
ready
[small] loop thru all
const all = getAllBuckets()
const excludedLookup = new Set(all.slice(0, 10))
const included = []

for (const b of all) {
	if (!excludedLookup.has(b)) {
		included.push(b)
	}
}
ready
[small] loop through excluded
const all = getAllBuckets()
const allSet = new Set(all)

for (const b of all.slice(10)) {
	allSet.delete(b)
}

const done = Array.from(allSet)
ready

Revisions

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