Try/Catch vs null check (v2)

Revision 2 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()
} catch(e) {
	/* ... */
}

return true;
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.