Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
exception flow control vs. if-else
A comparison between utilizing a thrown exception to control flow vs. an if-else.
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Browser:
Firefox 140
Operating system:
Windows
Device Platform:
Desktop
Date tested:
10 months ago
Test name
Executions per second
try-catch control flow (no exception)
3050983936.0 Ops/sec
try-catch control flow (thrown exception)
1195113.9 Ops/sec
if-else (hits if)
3590598912.0 Ops/sec
if-else (hits else)
3620512512.0 Ops/sec
Tests:
try-catch control flow (no exception)
const ok = true; let res; try { if (!ok) { throw new Error('ok = false'); } res = 1 + 1; } catch (e) { res = 1 + 2; }
try-catch control flow (thrown exception)
const ok = false; let res; try { if (!ok) { throw new Error('ok = false'); } res = 1 + 1; } catch (e) { res = 1 + 2; }
if-else (hits if)
const ok = true; let res; if (ok) { res = 1 + 1; } else { res = 1 + 2; }
if-else (hits else)
const ok = false; let res; if (ok) { res = 1 + 1; } else { res = 1 + 2; }