Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs Property dot notation + optional chain
(version: 0)
Comparing performance of:
Lodash get vs Native
Created:
one year 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', meta: { a: { b: 1 } } };
Tests:
Lodash get
_.get(person, 'meta.a');
Native
person.meta?.a
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:
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/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash get
6591963.0 Ops/sec
Native
33855256.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested. **What is being tested?** The provided JSON represents a microbenchmark that compares two approaches: 1. **Lodash `_.get()`**: A function from the Lodash library, which provides utility functions for functional programming in JavaScript. 2. **Property dot notation + optional chain**: A native JavaScript syntax that allows accessing nested properties of an object. **Options being compared** The benchmark tests the execution performance of both options: * **Lodash `_.get()`**: Uses the Lodash library to access the nested property. * **Native (property dot notation)**: Uses the native JavaScript syntax to access the nested property, taking advantage of optional chaining (`?.`) introduced in ECMAScript 2020. **Pros and Cons** Here's a brief overview of each approach: ### Lodash `_.get()` Pros: * Portable: Works across different browsers and environments. * Easy to use: Simple syntax, especially when dealing with complex object structures. Cons: * External dependency: Requires loading the Lodash library, which can add overhead. * Performance: May be slower due to the additional function call and argument processing. ### Native (property dot notation + optional chain) Pros: * Lightweight: No external dependencies or overhead. * Efficient: Native syntax is generally faster, especially for simple access patterns. Cons: * Browser support: Requires a modern browser that supports ECMAScript 2020 features. * Complexity: Syntax can become more complex when dealing with deeply nested objects. **Other considerations** * **Libraries**: Lodash is a popular utility library for JavaScript, providing various functions for functional programming. In this benchmark, the `_.get()` function is used to access a nested property in an object. * **JavaScript features**: The test leverages ECMAScript 2020's optional chaining (`?.`) feature, which allows accessing nested properties without explicitly specifying the entire path. **Other alternatives** If you're interested in alternative approaches or want to explore more performance optimizations, consider: * Using other utility libraries like `lodash-es` (a ES module version of Lodash) or `underscore.js`. * Implementing your own optimized solution using native JavaScript syntax. * Experimenting with other performance optimization techniques, such as code splitting or lazy loading. Keep in mind that each approach has its trade-offs and might be better suited for specific use cases.
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 longer path
Comments
Confirm delete:
Do you really want to delete benchmark?