EndsWith vs Set

Benchmark created on


Setup

const list = ["aaa.com", "bbb.com", "ccc.com", "ddd.com", "eee.com", "fff.com", "ggg.com", "hhh.com", "sss.com", "xxx.com", "yyy.com", "zzz.com"];
const set = new Set(list)
const checkInListWithEndsWith = (referrer) => {
	for (const domain of list) {
		if (referrer.endsWith(domain)) {
			return true;
		}
	}
	return false;
}
const checkInSet = (referrer) => set.has(referrer)

Test runner

Ready to run.

Testing in
TestOps/sec
EndsWith
const referrer = "foo.bar";
checkInListWithEndsWith(referrer);
ready
Set
const referrer = "foo.bar";
checkInSet(referrer);
ready

Revisions

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