Try/Catch vs null check (v3)

Revision 3 of this 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;
}

function getTexture() {
	return {};
}

Test runner

Ready to run.

Testing in
TestOps/sec
Try/Catch
try {
	getTexture()
	return true;
} catch(e) {
	/* ... */
	return false;
}
ready
Null check
if (getTexture() === null) {
	return false;
}

return true;
ready

Revisions

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