Using exceptions for control flow

Benchmark created on


Setup

returnPlainly = () => {
	return 'A'
}

processUsingIfElse = () => {
	var code = returnPlainly()
	if (code === 'A')
		return 'A returned'
	else
		return 'A not found'
}

returnUsingThrow = () => {
	throw new Error('A')
}

processUsingTryCatch = () => {
	try {
		returnUsingThrow()
	} catch(e) {
		if (e.message === 'A')
			return 'A returned'
		else
			return 'A not found'
	}
}

Test runner

Ready to run.

Testing in
TestOps/sec
if-else
processUsingIfElse();
ready
try-catch
processUsingTryCatch();
ready

Revisions

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