Exception Performance (v2)

Revision 2 of this benchmark created on


Description

Trying to evaluate how slow exceptions are in JS land

Setup

const myErrorFunc = (state) => {
	if (state) return true;
	throw new Error("bad state");
}

const myBoolFunc = (state) => {
	if (state) return true;
	return false;
}

Test runner

Ready to run.

Testing in
TestOps/sec
Bools
let state = false;

for(let i = 0; i < 1000; i++) {
	state = !state;
	try {
		const retVal = myBoolFunc(state);	
	} catch(e) {
		const retVal = false;
	}
}
ready
Errors
let state = false;

for(let i = 0; i < 1000; i++) {
	state = !state;
	try {
	    const retVal = myErrorFunc(state);	
	} catch(e) {
		const retVal = false;
	}
}
ready

Revisions

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