Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs Property dot notation vs Own get coded manually
(version: 0)
Comparing performance of:
Lodash get vs Native vs Own get
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', sub: { test: "oui", subsub: { en: "yes", fr: "oui"} }};
Tests:
Lodash get
_.get(person, 'sub.subsub.en');
Native
person.sub.subsub.en
Own get
function get(object, path, defaultValue) { // Divisez le chemin en un tableau de clés de propriété const keys = path.split('.'); // Parcourez les clés de propriété pour accéder à la valeur let value = object; for (const key of keys) { if (value == null) { return defaultValue; } value = value[key]; } // Si la valeur est nulle ou indéfinie, retournez la valeur par défaut if (value == null) { return defaultValue; } // Sinon, retournez la valeur trouvée return value; } get(person, 'sub.subsub.en');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash get
Native
Own 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):
Let's break down the provided benchmark and its options. **Benchmark Overview** The benchmark compares three approaches for accessing nested properties in an object: 1. **Lodash.get**: A function from the Lodash library that provides a safe way to access nested properties. 2. **Property dot notation**: Directly accessing a property using the `.` operator, e.g., `person.sub.subsub.en`. 3. **Own get coded manually**: A custom implementation of the "own get" method, which is used by JavaScript engines to access own properties. **Options Comparison** Here's an overview of each option: 1. **Lodash.get**: * Pros: Provides a safe way to access nested properties, handles null and undefined values, and is generally faster than manual implementations. * Cons: Requires including the Lodash library, which may add overhead. 2. **Property dot notation**: * Pros: Fast and efficient, as it only involves a single property lookup. * Cons: May throw errors if the nested properties don't exist, and can be brittle if the property names change. 3. **Own get coded manually**: * Pros: Native implementation that doesn't require any additional libraries or overhead. * Cons: Requires manual error handling for missing properties, which can lead to performance issues. **Lodash Library** The Lodash library is a popular utility belt for JavaScript that provides various functions and methods for tasks like array manipulation, object manipulation, and more. In this benchmark, the `_.get` function is used to access nested properties safely and efficiently. **Own Get Method** The "own get" method is a native feature of JavaScript engines that allows you to access own properties without the need for explicit property lookups or manual error handling. However, in this benchmark, we're using a custom implementation of the "own get" method instead of relying on the native engine optimization. **Special JS Feature/Syntax** There's no special JavaScript feature or syntax used in this benchmark beyond the standard ECMAScript syntax. **Benchmark Results** The latest benchmark results show that: * The **Native** option (property dot notation) is the fastest, with approximately 11.5 executions per second. * The **Own get** option has a slightly lower execution rate than Lodash.get and Native, but still faster than the latter. * The **Lodash.get** option is slower than the other two options, likely due to the added library overhead. **Alternatives** If you're interested in exploring alternative approaches for accessing nested properties, some options include: * Using a library like jQuery or MooTools that provides similar functionality to Lodash. * Implementing your own custom solution using JavaScript's built-in `in` operator and `hasOwnProperty` method. * Using a different language or framework that provides native support for nested property access. Keep in mind that these alternatives may have their own trade-offs in terms of performance, complexity, and feature set.
Related benchmarks:
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?