Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash get vs myget function
(version: 0)
test
Comparing performance of:
lodash get vs custom get
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script>https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.19/lodash.core.js</script>
Script Preparation code:
var a = {a:{b:{c:20}}};
Tests:
lodash get
let result = _.get(a, 'a.b.c', "");
custom get
const get = (mainObj, path, def=null) => { const newPath = path.split('.'); //[ 'a', 'b', 'c' ] for(let path of newPath){ mainObj = mainObj[path] } // newPath.forEach(path=>{ // mainObj = mainObj[path] //{a:{b:{c:20}}} //{b:{c:20}} //{c:20} // }) return mainObj }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash get
custom get
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
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition and test cases to explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Definition** The benchmark tests two approaches for accessing nested object properties in JavaScript: 1. `_.get` from Lodash 2. A custom implementation (`custom get`) written by the user Both approaches aim to retrieve a value from an object with a nested structure, using string paths (e.g., "a.b.c"). **Options Compared** The two options being compared are: * **Lodash `_.get`**: A utility function provided by the Lodash library. It's designed to safely navigate nested objects and retrieve values. * **Custom implementation (`custom get`)**: A hand-crafted solution written by the user, which also aims to access nested object properties. **Pros and Cons of Each Approach** **Lodash `_.get`** Pros: * Built-in utility function with optimized performance * Handles edge cases, such as undefined or null values * Provides a simple and concise way to navigate nested objects Cons: * Dependence on the Lodash library, which may not be included in all projects * May have licensing restrictions if used in commercial projects **Custom Implementation (`custom get`)** Pros: * Control over implementation details, such as performance optimizations * No dependence on external libraries or licenses * Can be tailored to specific use cases or requirements Cons: * Requires more code and maintenance effort * May not handle edge cases as robustly as `_.get` * Could lead to potential bugs or inconsistencies if not implemented correctly **Library Used** The Lodash library is used in the benchmark definition, specifically the `lodash.core.js` file. Lodash provides a wide range of utility functions for working with data structures, including arrays and objects. **Special JS Features/Syntax (None)** There are no special JavaScript features or syntaxes being tested in this benchmark. **Alternative Approaches** Other approaches to accessing nested object properties could include: * Using `in` operator with string concatenation * Utilizing recursion or iterative methods * Leveraging modern JavaScript features like `flatMap`, `map`, and `reduce` * Employing data structures like graphs or trees for nested objects Keep in mind that each approach has its trade-offs, and the best solution depends on the specific use case and performance requirements. In summary, this benchmark tests two approaches to accessing nested object properties: Lodash's `_.get` utility function and a custom implementation (`custom get`) written by the user. The pros and cons of each approach are discussed, highlighting the benefits and drawbacks of each method in terms of performance, maintainability, and licensing.
Related benchmarks:
Lodash.get vs Property dot notation my test
optional chaining vs lodash get
optional chaining vs lodash get
Lodash test suite
optional chaining chrome vs lodash get
Comments
Confirm delete:
Do you really want to delete benchmark?