Try/Catch Error Perf (v31)

Revision 31 of this benchmark created by db48x on


Preparation HTML

<script>
  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;
  }

function ifCheckShortCircuit(undef) {
    return undef && undef.prop;
}
</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
Short-Circuit Test
ifCheckShortCircuit();
ready

Revisions

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