Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
deeply nested Lodash.get vs Lodash.property vs native
(version: 0)
Comparing performance of:
Lodash get vs _property 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: 'Frederick', lastName: 'Corcino Alejo', a: { b: { c: { d: [{ e: { f: { g: "x" } } }] } } } }; var p = _.property("a.b.c.d[0].e.f.g");
Tests:
Lodash get
_.get(person, 'a.b.c.d[0].e.f.g');
_property
p(person);
native
person.a.b.c.d[0].e.f.g;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash get
_property
native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash get
4691859.5 Ops/sec
_property
5461787.0 Ops/sec
native
23023220.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark measures the performance of three different ways to access a deeply nested object: using Lodash's `property` function (`_property`), Lodash's `get` function (`Lodash get`), and accessing the property directly using dot notation (`native`). **Options Compared** * **Native**: Directly accessing the property using dot notation. * **_Property**: Using Lodash's `property` function to access the nested object. * **Lodash get**: Using Lodash's `get` function to access the nested object. **Pros and Cons of Each Approach** 1. **Native**: * Pros: Simple, efficient, and easy to understand. * Cons: May be less readable or maintainable for complex objects. 2. **_Property_ (Lodash)**: * Pros: Can handle more complex object structures using dot notation-like syntax. * Cons: Requires an additional library (Lodash) and may have a slight overhead due to function call. 3. **Lodash get**: * Pros: Provides a concise way to access nested objects with optional default values and can be used for more complex scenarios. * Cons: Requires the Lodash library, which may add complexity. **Library and Purpose** In this benchmark, two libraries are involved: 1. **Lodash**: A popular utility library that provides functions like `property` and `get`. These functions simplify working with nested objects by providing a standardized way to access properties using dot notation-like syntax. 2. **No additional library is required for the native approach**, as it only relies on standard JavaScript features. **Special JS Feature or Syntax** The benchmark uses Lodash's `get` function, which introduces an additional syntax element (`_.get(person, 'a.b.c.d[0].e.f.g';`) that may be unfamiliar to some developers. However, this is a well-documented and widely used feature in the JavaScript community. **Other Considerations** When choosing between these approaches, consider the following: * Readability: Native dot notation might be more readable for simple cases, while `property` or `get` might be more suitable for complex scenarios. * Maintainability: Using `property` or `get` can make your codebase more maintainable by standardizing the way you access nested objects. * Performance: In general, native dot notation is likely to be the fastest approach, followed closely by `property`, and then `get`. However, this may vary depending on specific use cases and JavaScript engines. **Alternatives** If you're looking for alternatives to Lodash or want to explore other ways to access nested objects, consider the following: * Using a different utility library, such as jQuery's `.prop()` method. * Implementing your own functions or helper methods to access nested objects. * Utilizing modern JavaScript features like `Object destructuring` or `Array.prototype.map()`. Keep in mind that these alternatives might come with their own trade-offs regarding performance, readability, and maintainability.
Related benchmarks:
Lodash.get vs Property dot notation with sanity check
Lodash.get vs Property deep
Lodash.get vs Property dot notation @movlan
Lodash.get vs Property dot notation with longer path
Comments
Confirm delete:
Do you really want to delete benchmark?