Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs native with optional chaining
(version: 0)
Comparing performance of:
Lodash get vs Native
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var person = {name: { firstName:'Frederick', lastName: 'Corcino Alejo' } };
Tests:
Lodash get
_.get(person, 'name.firstName'); _.get(person, 'name.nothing');
Native
person.name.firstName person.name?.nothing
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash get
Native
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!
Autogenerated LLM Summary
(model
gemma2:9b
, generated one year ago):
This benchmark compares the performance of two approaches for accessing nested properties in a JavaScript object: **1. Lodash's `_.get()`:** This function from the Lodash library is designed to safely access deeply nested properties in objects. It returns the value at the specified path, or a default value if the path doesn't exist. * **Pros:** - Safe and predictable: Handles missing paths gracefully without throwing errors. - Versatile: Can handle complex nested paths with multiple levels. * **Cons:** - Adds a dependency on Lodash library. - Can be slightly slower than native options in simple cases. **2. Native JavaScript with Optional Chaining (`?.`)**: Introduced in ES2020, optional chaining provides a concise and elegant way to access nested properties while preventing errors when paths are missing. It returns `undefined` if any property along the path is `undefined`. * **Pros:** - No external dependencies: Built-in to modern JavaScript. - Concise syntax: More readable for simple chains. - Often faster than Lodash in basic scenarios. * **Cons:** - Limited to ES2020+ environments: May not work in older browsers. **Benchmark Results:** The benchmark results show that native optional chaining (`?.`) is significantly faster (6.5 times) than Lodash's `_.get()` for this specific use case. However, keep in mind that performance can vary depending on the complexity of the object structure and the number of properties being accessed. **Alternatives:** - If compatibility with older browsers is crucial, you might consider using a polyfill for optional chaining or explore other libraries like Ramda which offer similar functionality. Let me know if you have any more questions!
Related benchmarks:
Lodash vs native
Comparing performance of: Lodash get vs Native with object checking
Lodash.get vs Property dot notation @movlan
Lodash.get vs Property dot notation with longer path
Lodash.get vs Optional chaining 1234
Comments
Confirm delete:
Do you really want to delete benchmark?