Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.get vs native 2022
(version: 0)
Comparing performance of:
Lodash get vs Native
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Script Preparation code:
var person = {name: 'Frederick', lastName: 'Corcino Alejo', foo: { bar: "baz" } };
Tests:
Lodash get
_.get(person, 'foo.bar');
Native
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
Native
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 explain what's being tested, compared, and some considerations. **Benchmark Overview** The benchmark compares two approaches to access nested properties in JavaScript: 1. Lodash (`_.get` method) 2. Native syntax (using optional chaining `?.`) **Lodash `.get` Method** Lodash is a utility library that provides various helper functions for tasks like string manipulation, array manipulation, and more. The `.get` method is specifically designed to access nested properties in an object. In the benchmark, Lodash is included using a CDN link, and the script preparation code defines a simple `person` object with nested properties (`foo.bar`). The test case uses the `_get` method to access `foo.bar`. **Native Syntax (Optional Chaining)** The native syntax for accessing nested properties in JavaScript has been introduced in ECMAScript 2020. It allows you to access nested properties using a more concise syntax, making your code more readable and expressive. In this benchmark, the test case uses the native syntax (`person?.foo?.bar`) to access `foo.bar`. **Comparison** The two approaches are compared in terms of performance (number of executions per second). **Pros and Cons** **Lodash `.get` Method:** Pros: * More explicit and readable way to access nested properties * Can be useful when working with complex data structures Cons: * Adds extra overhead due to the library being loaded * May not be as efficient as native syntax for simple cases Native Syntax (Optional Chaining): Pros: * More concise and expressive way to access nested properties * Efficient and optimized by the JavaScript engine Cons: * May require more parentheses or chaining, making it less readable in some cases * Not all browsers support ECMAScript 2020 features **Other Considerations** * The benchmark uses Chrome 104 as the browser, which supports both Lodash and native syntax. * The test case is run on a Linux desktop platform, which may affect performance due to the operating system and hardware characteristics. **Alternatives** If you're interested in exploring other alternatives, consider: * Other utility libraries like `lodash-es` or `ramda`, which offer similar functionality * Using JavaScript built-in methods like `in` and `hasOwnProperty` for accessing nested properties (although less readable and concise) * Caching or memoization techniques to reduce the number of property accesses Keep in mind that benchmarking results can vary depending on the specific use case, data structure, and performance requirements.
Related benchmarks:
Comparing performance of: Lodash get vs Native with object checking
Lodash.get vs native [Krosnoz]
Lodash.get vs Property dot notation @movlan
Lodash.get vs Lodash.property vs native vs native with optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?