Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs Property dot notation2
(version: 0)
Comparing performance of:
Lodash get vs Native
Created:
6 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 = {man: {name: 'Frederick', lastName: 'Corcino Alejo', friend: { name: "test", friend: { name: "another1" } } }};
Tests:
Lodash get
_.get(person, 'man.friend.friend.name');
Native
person.man.friend.friend.name
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:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash get
13612234.0 Ops/sec
Native
190763792.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the benchmark. **What is being tested?** The provided JSON represents a JavaScript microbenchmark that compares two approaches for accessing nested properties in an object: 1. **Property dot notation**: A native JavaScript syntax where you access nested properties using dots (.) to separate levels. 2. **Lodash's `_.get()` method**: A utility function from the Lodash library, specifically designed to safely navigate and retrieve nested properties. **Options comparison** The two approaches are compared in terms of execution speed and performance: * **Native Property Dot Notation**: This is a native JavaScript syntax that uses dot notation (`person.man.friend.friend.name`) to access nested properties. It's the most straightforward way to access properties, but it might be slower due to the need for multiple property lookups. * **Lodash's _.get() Method**: Lodash provides an optimized way to access nested properties using its `_.get()` method (`_.get(person, 'man.friend.friend.name')`). It offers more flexibility and safety features than native dot notation, but might incur a slight performance overhead due to the additional function call. **Pros and Cons** * **Native Property Dot Notation:** * Pros: * Fastest execution speed (native JavaScript syntax) * Fewer dependencies required * Cons: * Less readable code, especially for complex nested property access * Might be slower due to multiple property lookups * **Lodash's _.get() Method:** * Pros: * More readable and maintainable code (especially for complex nested properties) * Offers additional safety features, such as handling undefined or missing properties * Cons: * Slightly slower execution speed due to the function call overhead **Library: Lodash** The `_.get()` method is part of the Lodash library, a popular JavaScript utility library. Lodash provides various functions for tasks like: * Array manipulation * String manipulation * Object manipulation (like the `_.get()` method) * Functional programming utilities You can include Lodash in your project by adding the following script tag to your HTML file: ```html <script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script> ``` **Special JS feature or syntax** There is no special JavaScript feature or syntax used in this benchmark that requires explanation. **Other alternatives** If you prefer not to use Lodash, you can also implement the equivalent functionality using native JavaScript methods like `in` and `hasOwnProperty()` for property access. However, this approach would likely be slower than using the `_.get()` method from Lodash or native dot notation. For example: ```javascript function getProperty(obj, path) { const props = path.split('.'); for (const prop of props) { if (!obj.hasOwnProperty(prop)) return undefined; obj = obj[prop]; } return obj; } // Usage: const person = { man: { friend: { name: 'test' } } }; console.log(getProperty(person, 'man.friend.name')); // Output: "test" ``` This implementation is less readable and less maintainable than using the `_.get()` method or native dot notation.
Related benchmarks:
Lodash.get vs Property dot notation
Lodash.get vs Property dot notation with sanity check
Lodash.get vs Property dot notation for defaults
Lodash.get vs Property dot notation @movlan
Lodash.get vs Property dot notation with ?
Comments
Confirm delete:
Do you really want to delete benchmark?