Key set vs partitioned set (v4)

Revision 4 of this benchmark created on


Setup

const a = [];

for (i = 0; i <= 1_000_000; i++) {
	a.push({tag: "a", value: i});
}

for (i = 0; i <= 1_000_000; i++) {
	a.push({tag: "b", value: i});
}

Test runner

Ready to run.

Testing in
TestOps/sec
Key set
const makeKey = (val) => `${val.tag}${val.value}`;

const s = new Set(a.map(makeKey));

const lookup = (val) => s.has(makeKey(val));

for (const i of a) {
	lookup(i)
}
ready
partitioned set
const setA = new Set();
const setB = new Set();

for (const i of a) {
	if (i.tag === "a") {
		setA.add(i.value);
	} else {
		setB.add(i.value);
	}
}

const s = {setA, setB};

const lookup = (val) => {
	if (val.tag === "a") {
		return s.setA.has(val.value)
	} else {
		return s.setB.has(val.value)
	}
}

for (const i of a) {
	lookup(i);
}
ready

Revisions

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