Try/Catch vs null check (v7)

Revision 7 of this benchmark created on


Description

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

Setup

function getTextureError() {
	if (Math.random() < 0.0001)
	  throw new Error('Could not create WebGL Texture');
}

function getTextureNull() {
	return null;
}

function getTexture() {
	return Math.random() < 0.0001 ? null : {}
}

Test runner

Ready to run.

Testing in
TestOps/sec
Try/Catch
try {
	  getTextureError()
} catch(e) {
}
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.