Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lodash.get vs Property dot notation deeply vs optional chaining
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/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Lodash get
2756077.8 Ops/sec
Native naive
16482294.0 Ops/sec
Guarded native
3626380.2 Ops/sec
Shimmed get.
917644.2 Ops/sec
Optional chaining
16448768.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', details: {eyes: 'brown', hobbies: ['skiing', 'cooking']}};
Tests:
Lodash get
_.get(person, 'details.hobbies.1');
Native naive
person.details.hobbies[1]
Guarded native
person && person.details && person.details.hobbies && person.details.hobbies.length && person.details.hobbies[1]
Shimmed get.
const get = (obj, path, defaultValue) => { const result = String.prototype.split.call(path, /[,[\].]+?/) .filter(Boolean) .reduce((res, key) => (res !== null && res !== undefined) ? res[key] : res, obj); return (result === undefined || result === obj) ? defaultValue : result; }; get(person, 'details.hobbies.1');
Optional chaining
person?.details?.hobbies?.[1]