Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash.get vs optional chaining 2
(version: 0)
Compare lodash.get to babel transpiled ?. (optional chaining) operator
Comparing performance of:
lodash.get vs Optional chaining (babel es2015)
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var state = { wrapped1: { wrapped2: { location: { search: '', id: 12 } } }, data: {} };
Tests:
lodash.get
var l = _.get(state, ['wrapped1','wrapped2','location','search']);
Optional chaining (babel es2015)
var s = state?.wrapped1?.wrapped2?.location?.search;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash.get
Optional chaining (babel es2015)
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0
Browser/OS:
Chrome 128 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash.get
8989201.0 Ops/sec
Optional chaining (babel es2015)
28414048.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark compares two approaches: `lodash.get` and optional chaining (`?.`) with Babel transpiled ES2015 syntax. **Options Being Compared** 1. **Lodash.get**: A utility function from the Lodash library, which provides a way to safely access nested properties of an object. 2. **Optional Chaining (babel es2015)**: A new feature in JavaScript that allows you to access nested properties without explicitly typing the chain of property accesses. **Pros and Cons** * **Lodash.get**: + Pros: Can handle cases where the nested property is missing or null, preventing errors. + Cons: Introduces additional overhead due to the function call and potential performance impact. * **Optional Chaining (babel es2015)**: + Pros: More concise and readable way to access nested properties, reducing the risk of null pointer exceptions. + Cons: Requires support for ES2015 syntax and Babel transpilation, which might add complexity. **Library Used** The `lodash.get` function is used from the Lodash library. Lodash is a popular utility belt for JavaScript that provides various helper functions, including data manipulation, string manipulation, and more. **Special JS Feature or Syntax** In this benchmark, optional chaining (`?.`) with Babel transpiled ES2015 syntax is being tested. Optional chaining allows you to access nested properties without explicitly typing the chain of property accesses, e.g., `state.wrapped1.wrapped2.location.search`. This feature was introduced in ECMAScript 2020 (ES2020) and is supported by most modern browsers. **Other Alternatives** If you need an alternative to `lodash.get`, you could consider using other libraries like: * **`_.at`**: Another Lodash function that provides a way to access nested properties, but with some differences in behavior. * **`Array.prototype.at`**: A method introduced in ECMAScript 2020 (ES2020) that allows accessing array elements by their index and key, which might be relevant for nested object access. However, these alternatives might not provide the same level of safety and convenience as `lodash.get`. **Test Preparation Code** The test preparation code defines a sample object (`state`) with nested properties. The HTML preparation code includes a script tag that loads the Lodash library, which is used by the `lodash.get` function. Overall, this benchmark provides a useful comparison between two approaches to accessing nested properties in JavaScript, highlighting the trade-offs between safety, conciseness, and performance.
Related benchmarks:
lodash.get vs optional chaining
ES6 Optional Chaining vs TS Optional Chaining result in javascript vs vs. Lodash _.get
lodash.get vs optional chaining(babel) vs optional chaining(es2020) vs Without Optional chaining
lodash.get vs optional chaining v2
Comments
Confirm delete:
Do you really want to delete benchmark?