If vs switch (v6)

Revision 6 of this benchmark created on


Setup

const data = [...Array(1000).keys()].map(String)

Test runner

Ready to run.

Testing in
TestOps/sec
Just if
function ifelse(value) {
	if (value === "123") return "is 123"
	else if (value.includes("5")) return "has 5"
	else if (/[02468]^/.test(value)) return "is even"
	else return "something else"
}


data.forEach(ifelse)
ready
Just if reversed
function justif(value) {
	if (/[02468]^/.test(value)) return "is even"
	if (value === "123") return "is 123"
	if (value.includes("5")) return "has 5"
	return "something else"
}


data.forEach(justif)
ready

Revisions

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