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

Revision 11 of this benchmark created 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 = 1for(i=0;i<1000;i++){
n+=1;
var z=n*n*n*n/n;
}
}

function error(){
    return null;        
}
</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
pure
test();
ready

Revisions

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