Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs object-path vs Property dot notation
(version: 1)
Modified from https://gist.github.com/acao/018fa0943da0e39c96f57fca64cd0c02
Comparing performance of:
Lodash get vs object path vs Native
Created:
3 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.4/lodash.min.js" type="text/javascript"></script> <script src="https://cdn.rawgit.com/mariocasciaro/object-path/master/index.js"></script>
Script Preparation code:
var obj = { stuff: { things: { stuff: 'things', things: 'stuff', other: { stuff: 'things' } } } };
Tests:
Lodash get
_.get(obj, 'stuff.things.other.stuff');
object path
objectPath.get(obj, 'stuff.things.other.stuff');
Native
obj.stuff && obj.stuff.things && obj.stuff.things.other && obj.stuff.things.other.stuff;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash get
object path
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0
Browser/OS:
Firefox 138 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash get
8003145.0 Ops/sec
object path
1885805.6 Ops/sec
Native
871163456.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The MeasureThat.net benchmark tests the performance of three different approaches to access nested properties in an object: Lodash's `_.get()` method, the `object-path` library, and native JavaScript property access (also known as "dot notation"). **Approaches Compared** 1. **Lodash get**: This approach uses the `_.get()` function from Lodash to dynamically access the nested property. 2. **Object-Path**: This approach uses a library called `object-path` to access the nested property. The library provides a simple and efficient way to traverse objects using a dot notation-like syntax. 3. **Native (Dot Notation)**: This approach uses native JavaScript property access, where the developer explicitly writes the dot notation to access the nested property. **Pros and Cons of Each Approach** 1. **Lodash get**: * Pros: + Easy to use and understand + Provides a simple way to access nested properties with error handling * Cons: + Adds an additional dependency (the Lodash library) + May be slower than native JavaScript due to the overhead of function calls 2. **Object-Path**: * Pros: + Fast and efficient, as it uses a optimized implementation under the hood + Provides a simple and consistent way to traverse objects using a dot notation-like syntax * Cons: + May require additional setup (installing the library) and configuration + Less intuitive for developers who are not familiar with the library's API 3. **Native (Dot Notation)**: * Pros: + Fastest option, as it bypasses any overhead of libraries or function calls + Most intuitive for developers who are already comfortable with dot notation * Cons: + Requires explicit and verbose code to access nested properties + Less readable and maintainable than other approaches **Library: Object-Path** The `object-path` library is a lightweight JavaScript library that provides a simple and efficient way to traverse objects using a dot notation-like syntax. It is designed to be fast, consistent, and easy to use, making it a popular choice for developers who need to work with complex object graphs. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntax used in this benchmark. **Benchmark Results Interpretation** The benchmark results show the performance of each approach on a specific test case. The "Native" (Dot Notation) result is the fastest, followed by the `object-path` library, and then Lodash's `_.get()` method. This suggests that native JavaScript property access is the most efficient option for this particular use case. **Alternatives** Other alternatives to accessing nested properties in objects include: * Using a custom function or utility to traverse the object graph * Using a different library or framework that provides similar functionality (e.g., React's `useSelector()` hook) * Optimizing the code for performance using techniques like memoization, caching, or parallel processing
Related benchmarks:
Lodash.get vs Property dot notation
isEmpty vs Object.keys
Lodash.get vs Property dot notation for complex data
Lodash.get vs Property dot notation vs Own get coded manually
Lodash.get vs Property dot notation with longer path
Comments
Confirm delete:
Do you really want to delete benchmark?