test try catch vs manual checking

JavaScript performance comparison

Test case created by xiel

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var emptyObj = {}
  var filledObj = {
    bli: 1,
    bla: {
      blubb: 3
    }
  };
  
  function op(getValue) {
    var value = undefined;
    try {
      value = getValue();
    }
    catch (e) { }
    return value;
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
emptyObj, manual
if (emptyObj && emptyObj.bla && emptyObj.bla.blubb) {
	return emptyObj.bla.blubb;
} else {
  return;
}
pending…
emptyObj, try...catch
return op(() => emptyObj.bla.blubb);
pending…
filledObj, manual
if (filledObj && filledObj.bla && filledObj.bla.blubb) {
	return filledObj.bla.blubb;
} else {
  return
}
pending…
filledObj, try...catch
return op(() => filledObj.bla.blubb);
pending…

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

Compare results of other browsers

0 Comments