Try/Catch Error Perf
JavaScript performance comparison
Preparation code
<script>
function tryCatch(undef) {
try {
return undef.prop;
} catch (ex) {
return null;
}
}
function ifCheck(undef) {
if (undef !== undefined) {
return undef.prop;
} else {
return null;
}
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Try Catch |
|
pending… |
If Check |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 2: published
- Revision 3: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 11: published
- Revision 12: published
- Revision 16: published by unfo-
- Revision 17: published
- Revision 18: published
- Revision 19: published
- Revision 21: published
- Revision 22: published by Ben Gillies
- Revision 23: published
- Revision 24: published
- Revision 26: published
- Revision 30: published by Jason McAffee
- Revision 31: published by db48x
- Revision 33: published
- Revision 34: published
- Revision 35: published
- Revision 36: published
- Revision 38: published
- Revision 39: published
- Revision 40: published by Josh
- Revision 41: published by Tan Nhu
- Revision 42: published
- Revision 43: published
- Revision 44: published by Nick Pepper
- Revision 45: published
- Revision 46: published
- Revision 47: published
- Revision 48: published by bam and last updated
- Revision 49: published
- Revision 50: published
- Revision 51: published
- Revision 52: published
- Revision 53: published
- Revision 54: published by jdavid
- Revision 55: published
- Revision 56: published
- Revision 57: published
- Revision 58: published
1 comment
Interesting test, although as an error is raised each time in the 'try catch' test, they don't really do the same thing under the hood. It's also interesting to see that even if we don't enter the catch clause, try / catch is still slower, although the difference appears to be less important (http://jsperf.com/trycatch-with-no-error-raised)