Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lodash.get vs safeGet vs Null operator
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser:
Chrome 130
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Lodash get
3909920.2 Ops/sec
safeGet
5441086.0 Ops/sec
Null operator
13355003.0 Ops/sec
Or Operator
17453662.0 Ops/sec
Direct
17486466.0 Ops/sec
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var person = {name: 'Frederick', lastName: 'Corcino Alejo', nested: {name: 'test'}}; function safeGet(obj, path, defaultValue) { return path.split('.').reduce((xs, x) => (xs && xs[x]) ? xs[x] : defaultValue, obj); }
Tests:
Lodash get
_.get(person, 'name', ''); _.get(person, 'nested.name', '');
safeGet
safeGet(person, 'name', ''); safeGet(person, 'nested.name', '');
Null operator
person?.name ?? ''; person?.nested?.name ?? '';
Or Operator
person?.name || ''; person?.nested?.name || '';
Direct
person.name; person.nested.name;