Throwing vs. Branching: Unhappy Path

Benchmark created on


Description

A demonstration of how bad branch-to-throw-to-branch is. This is found in all popular fetch() wrappers like axios and ky.

Test runner

Ready to run.

Testing in
TestOps/sec
Throwing - What fetch() wrappers do
const x = false;
try {
	// What wrappers do:  Throw if response.ok is false
	if (!x) {
		throw new Error("x is false");
	}
}
catch {
	// What wrapper consumers want to do.
	console.log('x is false');
}
ready
Not throwing
const x = false;
if (!x) {
	console.log('x is false')
}
ready

Revisions

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