Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
testing the performance of try catch vs check for undefined
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:125.0) Gecko/20100101 Firefox/125.0
Browser:
Firefox 125
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
using try catch block
10146887.0 Ops/sec
using check
59776.7 Ops/sec
Tests:
using try catch block
const obj = { obj : { obj: { obj: { obj: 1 } } } } for (let i=0; i<99; i++) { try { const val = obj.obj.obj.obj.obj; } catch (e) { //do nothing } }
using check
const obj = { obj : { obj: { obj: { obj: 1 } } } } const getNested = obj => (path) => { const arr = path.split('.'); return arr.reduce( (root, key) => ((root && root[key] !== 'undefined') ? root[key] : undefined), obj, ); }; for (let i=0; i<99; i++) { getNested(obj)('obj.obj.obj.obj'); }