If vs switch (v7)

Revision 7 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"
	if (value.includes("5")) return "has 5"	
	if (/[02468]$/.test(value)) return "is even"
	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
Testi with simple odd test
function justif(value) {
	if ( !(value.charCodeAt(value.length-1) & 1) ) 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.