Try/Catch Error Perf (v30)

Revision 30 of this benchmark created by Jason McAffee on


Preparation HTML

<script>
  //show test results for most likely scenario
  var testWithValue = {prop:'test'};

  function tryCatch(undef) {
    try {
      return undef.prop;
    } catch (ex) {
      return null;
    }
  }

  function ifUndefinedCheck(undef) {
    if (undef !== undefined) {
      return undef.prop;
    } else {
      return null;
    }
  }
function ifTypeofCheck(undef) {
    if (typeof undef !== 'undefined') {
      return undef.prop;
    } else {
      return null;
    }
  }

function ifCheckExists(undef) {
    if (undef) {
      return undef.prop;
    } else {
      return null;
    }
  }

function ifCheckTernary(undef) {
    return undef ? undef.prop :null;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Try Catch
tryCatch();
ready
If Undefined Check
ifUndefinedCheck();
ready
If Typeof Check
ifTypeofCheck();
ready
If Exists Check
ifCheckExists();
ready
Ternary Check
ifCheckTernary();
ready
Try Catch with Value
tryCatch(testWithValue);
ready
If Undefined Check with Value
ifUndefinedCheck(testWithValue);
ready

Revisions

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