Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash get with path vs native get with path
(version: 0)
Comparing performance of:
lodash vs native
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
var pathToResolve = 'a.b.c.d'; var objectToResolve = { a: { b: { c: 1 } } }; var get = (path, obj, defaultValue) => { let finalPath; if (Array.isArray(path)) { finalPath = path; } else if (typeof path === 'string') { finalPath = path.split('.'); } else { finalPath = []; // eslint-disable-next-line no-console console.warn('Invalid type of path', path); } return finalPath.reduce((xs, x) => ((xs && typeof xs[x] !== 'undefined') ? xs[x] : defaultValue), obj); };
Tests:
lodash
var result = _.get(pathToResolve, objectToResolve, false);
native
var result = get(pathToResolve, objectToResolve, false);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
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; rv:135.0) Gecko/20100101 Firefox/135.0
Browser/OS:
Firefox 135 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
2557615.2 Ops/sec
native
8279071.5 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 Overview** The benchmark measures the performance difference between using Lodash's `get()` function and a custom implementation of getting values from an object using a path. The test case uses two different approaches: 1. **Lodash**: Uses the official Lodash library, which provides a convenient way to access nested properties in objects. 2. **Native**: Implements a custom solution that manually handles string and array paths. **Options Being Compared** The benchmark compares the performance of two options: 1. **Lodash**: Utilizes the Lodash `get()` function to access nested properties. 2. **Native**: Manually implements getting values from an object using a path, without relying on a library. **Pros and Cons of Each Approach** ### Lodash Pros: * Highly optimized for performance * Well-tested and reliable * Reduces boilerplate code Cons: * Adds dependency on the Lodash library * May introduce overhead due to the library's complexity ### Native Pros: * No dependencies or overhead from a library * Can be highly customized and tuned for specific use cases * Reduces reliance on external libraries Cons: * Requires manual implementation of path handling logic * May result in more complex code * Potential performance overhead if not optimized correctly **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for common tasks, such as array manipulation, object traversal, and string processing. In this benchmark, Lodash's `get()` function is used to access nested properties in objects. The `get()` function takes three arguments: * `path`: The path to the desired value (string or array) * `obj`: The object to search for the value * `defaultValue`: The default value to return if the path is invalid **Special JS Feature/Syntax** None mentioned in this benchmark.
Related benchmarks:
ES6 Optional Chaining vs TS Optional Chaining result in javascript vs vs. Lodash _.get
lodash get vs native js
Lodash at vs Native
es6 destructuring vs lodash _.get string and array keys with toPath and manual caching 2
Comments
Confirm delete:
Do you really want to delete benchmark?