Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Try/catch performance for control flow #2
(version: 0)
Comparing performance of:
Try/catch vs Without try/catch vs Try/catch throwing a string
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div id="test"></div>
Tests:
Try/catch
function checkEven(num) { if (num % 2 === 0) { return true; } throw new Error('Number is odd'); } for (let i = 0; i < 1000;++i) { let res; try { checkEven(i); res = true; } catch (err) { res = false; } }
Without try/catch
function checkEven(num) { if (num % 2 === 0) { return true; } return false; } for (let i = 0; i < 1000;++i) { let res; if (checkEven(i)) { res = true; } else { res = false; } }
Try/catch throwing a string
function checkEven(num) { if (num % 2 === 0) { return true; } throw 'Number is odd'; } for (let i = 0; i < 1000;++i) { let res; try { checkEven(i); res = true; } catch (err) { res = false; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Try/catch
Without try/catch
Try/catch throwing a string
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
jQuery by id vs Document.getElementById
jQuery by class vs Document.getElementsByClassName
jQuery by id vs Document.getElementById
jQuery by id vs Document.getElementById123;
querySelector vs querySelectorAll vs getElementsByClassName vs querySelector (ID) vs getElementsByID 20x
Comments
Confirm delete:
Do you really want to delete benchmark?