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
Direct
17.5M/s
Or Operator
17.4M/s
Null operator
17.3M/s
safeGet
5.7M/s
Lodash get
3.9M/s
View exact numbers
Test name
Executions per second
✓
Direct
17,467,270 Ops/sec
Or Operator
17,397,892 Ops/sec
Null operator
17,298,478 Ops/sec
safeGet
5,681,454 Ops/sec
Lodash get
3,904,029 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;