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

Revision 10 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 = 1;  
}

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

Revisions

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