Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs Conditional property dot notation
(version: 0)
Comparing performance of:
Lodash get vs Conditional person
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'};
Tests:
Lodash get
const name = _.get(person, 'name');
Conditional person
const name = person?.name
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash get
Conditional person
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 benchmark and its test cases. **Benchmark Purpose** The benchmark measures the performance difference between using Lodash's `_.get()` function and the conditional property dot notation (`person?.name`) in JavaScript. The goal is to determine which approach is faster for accessing a nested property of an object. **Options Compared** There are two options compared: 1. **Lodash's _.get() function**: A utility function from the Lodash library that retrieves a value from an object using a path or key. 2. **Conditional property dot notation (`person?.name`)**: A shorthand syntax introduced in ECMAScript 2020, which allows accessing nested properties of objects with optional chaining. **Pros and Cons** * **Lodash's _.get() function**: + Pros: Well-tested, widely adopted, and provides a clear, explicit way to access nested properties. + Cons: Requires importing the Lodash library, adds overhead due to its object method call. * **Conditional property dot notation (`person?.name`)**: + Pros: Simplifies code, reduces clutter, and is a concise way to access nested properties. Also, it's a native JavaScript feature, so no additional libraries are needed. + Cons: May be less readable for developers unfamiliar with the syntax, as it relies on the optional chaining operator (`?.`), which was introduced relatively recently (ECMAScript 2020). **Library and Its Purpose** The Lodash library is a collection of utility functions that extend JavaScript's functionality. In this benchmark, `_.get()` is used to retrieve a value from an object using a path or key. **Special JS Feature/ Syntax** The conditional property dot notation (`person?.name`) uses the optional chaining operator (`?.`), which was introduced in ECMAScript 2020. This operator allows accessing nested properties of objects without throwing an error when the property is undefined. **Other Considerations** Other alternatives to using `_.get()` or the conditional property dot notation could include: * Using a different library, such as Underscore.js (a predecessor to Lodash) or js-obj (a lightweight object manipulation library). * Implementing custom logic for accessing nested properties. * Using a different JavaScript engine or compiler that optimizes the execution of these two approaches. **Benchmark Results** The benchmark results show that: * The `Conditional person` test, which uses the conditional property dot notation (`person?.name`), performs better than the `Lodash get` test. * Both tests are executed at a high rate (146 million and 42 million executions per second, respectively) on a Chrome 105 browser on a Mac OS X 10.15.7 machine. Keep in mind that these results may not be representative of all environments or browsers, as the benchmark is specific to this particular setup.
Related benchmarks:
Lodash.get vs Property dot notation
Lodash.get vs Property dot notation with sanity check
Lodash.get vs Property dot notation @movlan
Lodash.get vs Property dot notation with ?
Comments
Confirm delete:
Do you really want to delete benchmark?