Try/Catch Block vs. Custom tryCatch Function (v9)

Revision 9 of this benchmark created by Dan Popa on


Description

Investigating a means of replacing the try catch block with a custom solution for performance intensive operations.

Preparation HTML

<script>
var callback = null;
window.onerror = function(msg, file, line){
    var error = new Error(msg, file, line);
    if(callback){
        callback(error);
        callback = null;
    }
    return true;
};
        
function tryCatch(fn, fail){
    callback = fail;
    fn();
    callback = null;
}

function test(){
    var n = 1;  
}

function error(){
    return null;        
}
function nestedFunction() {
    var n = 1;
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Try/Catch Block
try{
    var n = 1;
}catch(e){}
ready
tryCatch Function (Anonymous)
tryCatch(function(){
    var n = 1;    
}, function(error){
    return null;
});
ready
tryCatch Function (Named)
tryCatch(test, error);
ready
nested function
try{
    nestedFunction();
}catch(e){}
ready

Revisions

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