Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash performance
(version: 0)
Comparing performance of:
lodash string path vs lodash array path vs native
Created:
4 years 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 testObj = { job: { employee: { fullName: 'arthur' } } };
Tests:
lodash string path
_.get(testObj, 'job.employee.fullName');
lodash array path
_.get(testObj, ['job', 'employee', 'fullName']);
native
testObj.job.employee.fullName
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash string path
lodash array path
native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash string path
4075223.2 Ops/sec
lodash array path
6527528.5 Ops/sec
native
21685100.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and analyze what's being tested. **Benchmark Definition** The benchmark is defined in two parts: Script Preparation Code and Html Preparation Code. The Script Preparation Code defines the JavaScript object `testObj` that will be used for the benchmark, while the Html Preparation Code includes a script tag that loads the Lodash library (`lodash.js`) from a CDN. **Options being compared** There are three test cases being compared: 1. **Lodash string path**: This test case uses the `_.get()` function to access a nested property of the `testObj` object using a dot notation (`_.get(testObj, 'job.employee.fullName');`). 2. **Lodash array path**: This test case uses the `_.get()` function to access a nested property of the `testObj` object using an array notation (`_.get(testObj, ['job', 'employee', 'fullName']);`). 3. **Native**: This test case accesses the same property directly without using Lodash (`testObj.job.employee.fullName`). **Pros and Cons** * **Lodash string path**: Using `_.get()` can provide a safer and more flexible way to access nested properties, as it allows for dynamic property names. However, it may introduce additional overhead due to the function call. * **Lodash array path**: Similar to the string path, using an array notation can be more readable and maintainable. However, it may also add some overhead due to the function call and the need to check if the input is an array. * **Native**: Directly accessing the property without Lodash is likely to be the fastest option, as it avoids any additional function calls or checks. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object iteration, and more. The `_.get()` function is part of this library and allows for safe and flexible access to nested properties in objects. **Special JS feature/syntax** None mentioned explicitly, but using dot notation (e.g., `testObj.job.employee.fullName`) is a common JavaScript syntax for accessing nested properties. Using square brackets (`[]`) for array notation (e.g., `_.get(testObj, ['job', 'employee', 'fullName'])`) is also a valid syntax. **Alternatives** Other alternatives to Lodash include: * **lodash-es**: An ES6-friendly version of Lodash. * **Ramda**: Another popular JavaScript utility library that provides a functional programming style for data processing and manipulation. * **Object.entries() and Object.at()**: Native JavaScript functions for working with objects, which can be used instead of Lodash's array notation. Note that the choice of alternative depends on the specific use case and personal preference.
Related benchmarks:
Object.assign vs Lodash.assign
Checks if value is an object
Lodash vs plain
lodash performance v2
Comments
Confirm delete:
Do you really want to delete benchmark?