Try/Catch Error Perf (v22)

Revision 22 of this benchmark created by Ben Gillies on


Preparation HTML

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

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

  function andOrCheck(undef) {
    return undef && undef.prop || null;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Try Catch
tryCatch(Object);
tryCatch();
ready
If Check
ifCheck(Object);
ifCheck();
ready
If type Check
ifTypeCheck(Object);
ifTypeCheck();
ready
And Or Check
andOrCheck(Object);
andOrCheck();
ready

Revisions

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