Try/Catch vs null check

Benchmark created on


Description

Measure performance of a try/catch block compared to a simple null check

Setup

function getTextureError() {
	throw new Error('Could not create WebGL Texture');
}

function getTextureNull() {
	return null;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Try/Catch
try {
	getTextureError()
} catch(e) {
	/* ... */
}
ready
Null check
if (getTextureNull() === null) {
	/* ... */
}
ready

Revisions

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