Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs Property dot notation deep
(version: 0)
Comparing performance of:
Lodash get vs Native
Created:
3 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', Deep: {VeryDeep: {UltraDeep: {result: true}}}};
Tests:
Lodash get
_.get(person, 'Deep.VeryDeep.UltraDeep.result');
Native
person?.Deep?.VeryDeep?.UltraDeep?.result
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
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of what's being tested in this JavaScript microbenchmark. **Benchmark Overview** The benchmark compares two ways to access nested properties in an object: using Lodash's `_.get()` function and native dot notation (also known as property chain syntax). **Options Compared** 1. **Lodash.get()**: This is a utility function from the popular Lodash library, which provides a safe way to navigate nested objects. 2. **Native Dot Notation**: This is the traditional way of accessing nested properties in JavaScript using dot notation (e.g., `person.Deep.VeryDeep.UltraDeep.result`). **Pros and Cons** ### Lodash.get() Pros: * Provides a safe and robust way to access nested properties, avoiding potential errors due to typos or missing properties. * Can handle cases where the property path is unknown at compile time. Cons: * Introduces an additional function call, which may incur overhead in terms of performance. * Requires including an extra library (Lodash) in the test environment. ### Native Dot Notation Pros: * Native to JavaScript and doesn't require any external libraries. * Typically faster than Lodash's `_.get()` since it avoids the function call overhead. Cons: * May throw errors if a property is missing or has a typo, requiring manual handling of errors. * Limited support for cases where the property path is unknown at compile time. **Other Considerations** * The benchmark assumes that the object being accessed (`person`) and its properties are known at runtime. * If the object structure is dynamic or unknown at compile time, Lodash's `_.get()` may be a better choice. * The use of optional chaining (`?.`) in native dot notation (e.g., `person?.Deep?.VeryDeep?.UltraDeep?.result`) provides some safety features but can still lead to errors if the property path is invalid. **Library Used** The benchmark includes Lodash version 4.16.0, which provides the `_.get()` function. **Special JS Feature or Syntax** The benchmark uses optional chaining (`?.`) in native dot notation, which was introduced in ECMAScript 2020 (ES10). Optional chaining allows accessing nested properties in a safer and more concise way, but its use is not required for older browsers or environments that don't support it. **Other Alternatives** For alternative ways to access nested properties, you can consider using other libraries like Underscore.js or other utility functions provided by modern JavaScript frameworks (e.g., React or Angular). Alternatively, you can implement your own utility function or use native array and object methods (e.g., `Array.prototype.indexOf()`, `Object.keys()`, and `JSON.parse()`) to access nested properties.
Related benchmarks:
Lodash.get vs Property dot notation
Lodash.get vs Property dot notation with sanity check
Lodash.get vs Property dot notation - 2 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?