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
Null operator
17.9M/s
Or Operator
16.7M/s
Direct
16.1M/s
safeGet
5.7M/s
Lodash get
4.0M/s
View exact numbers
Test name
Executions per second
✓
Null operator
17,936,112 Ops/sec
Or Operator
16,655,933 Ops/sec
Direct
16,088,180 Ops/sec
safeGet
5,734,194 Ops/sec
Lodash get
3,981,362 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;