Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash get vs. es6 fallback values
(version: 0)
Comparing performance of:
Lodash get vs es6 fallback values
Created:
4 years ago
by:
Registered User
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: 'Bob', lastName: 'Sponge', foo: { bar: "baz" } }; var p = _.property("foo.bar");
Tests:
Lodash get
const test = _.get(person, 'foo.bar', '');
es6 fallback values
const test =person.foo?.bar ?? ''
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash get
es6 fallback values
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash get
6595586.0 Ops/sec
es6 fallback values
29863386.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested, compared, and analyzed. **Benchmark Overview** The benchmark compares two approaches to accessing nested properties in JavaScript: Lodash's `get` function and ES6's optional chaining (`?.`) with nullish coalescing (`??`). **Test Cases** There are two test cases: 1. **Lodash get**: This test case uses the `_.get()` function from Lodash to access the `foo.bar` property of the `person` object. 2. **ES6 fallback values**: This test case uses ES6's optional chaining (`?.`) with nullish coalescing (`??`) to access the `foo.bar` property of the `person` object. **Comparison** The benchmark compares the performance of these two approaches on a given input (the `person` object). The comparison is likely done in terms of execution speed, which is measured by the number of executions per second. **Pros and Cons** * **Lodash get**: Pros: + More readable code (some developers might find it easier to understand than ES6's optional chaining). + Easier to use for nested property access. Cons: + Requires an external library (Lodash) which may add overhead due to download and parsing time. + Might be slower due to the additional processing required by the Lodash function. * **ES6 fallback values**: Pros: + Built-in functionality, so no additional overhead due to loading an external library. + Lightweight and efficient, as it only uses basic JavaScript operators (`?.` and `??`). Cons: + Requires knowledge of ES6 syntax, which might be unfamiliar to some developers. + Can lead to less readable code for nested property access. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions and helpers. In this benchmark, the `get()` function from Lodash is used to access nested properties in an object. The `get()` function returns undefined if any part of the path does not exist in the object. **Special JS feature: ES6 optional chaining** The test case using ES6's optional chaining (`?.`) with nullish coalescing (`??`) takes advantage of a new syntax introduced in ECMAScript 2018. This feature allows you to access nested properties without worrying about null or undefined values, making the code more concise and expressive. **Other alternatives** Other alternatives for accessing nested properties in JavaScript include: * Using `in` operator with bracket notation (e.g., `person['foo']['bar']`) * Using a simple recursive function * Using other utility libraries like jQuery or MooTools However, these alternatives might not be as efficient or readable as Lodash's `get()` function or ES6's optional chaining.
Related benchmarks:
Lodash.get vs Lodash.property vs native
Lodash.get vs Lodash.property vs native 2
Lodash.get vs Lodash.property vs native 3
Lodash.get vs Lodash.property vs native vs native with optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?