Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash get vs nullish coalescing
(version: 0)
Comparing performance of:
get existing property vs null coalescing existing property vs get non existing property vs null coalescing non existing property
Created:
2 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var result = ''; var data = { data: [ { user: { location: { address: { street: 'main street', }, }, }, }, ], }; const iterations = 100;
Tests:
get existing property
for (let i = 0; i < 100; i += 1) { result = _.get(data, 'data.0.user.location.address.street', ''); }
null coalescing existing property
for (let i = 0; i < 100; i += 1) { result = data?.data?.[0]?.user?.location?.address?.street ?? ''; }
get non existing property
for (let i = 0; i < 100; i += 1) { result = _.get(data, 'data.0.user.location.address.zip', ''); }
null coalescing non existing property
for (let i = 0; i < 100; i += 1) { result = data?.data?.[0]?.user?.location?.address?.zip ?? ''; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
get existing property
null coalescing existing property
get non existing property
null coalescing non existing property
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
lodash._get vs Property dot notation
Lodash.get using string vs array at depth 2
Lodash get vs. native optional chaining
_.get lodash vs babel optional chaining
Lodash.get vs Property dot notation for complex data
Comments
Confirm delete:
Do you really want to delete benchmark?