set difference (v4)

Revision 4 of this benchmark created on


Setup

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

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

const allBucket = getAllBuckets()

const excludedBucket = allBucket.slice(0, 200)

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(excludedBucket)
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 excludedBucket) {
	allSet.delete(b)
}

const done = Array.from(allSet)
ready
filter method small loop
const all = getAllBuckets()

const includedKeys = all.filter((bucket) => !excludedBucket.includes(bucket))
ready
filter method big loop
const all = getAllBuckets()

const includedKeys = all.filter((bucket) => !all.includes(bucket))
ready

Revisions

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