Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash at vs Native
(version: 0)
Comparing performance of:
Lodash vs Native
Created:
5 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 object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; var paths = ['a[0].b.c', 'a[1]']
Tests:
Lodash
var atValues = (object, paths) => _(object).at(paths).value(); atValues(object, paths)
Native
const atValues = (object, paths) => paths.map((path) => { const pathArr = path .toString() .split(/#?\[|\]|\./) .filter((p) => p !== '') let copyObj = { ...object } for (const p of pathArr) { if (Object.prototype.hasOwnProperty.call(copyObj, p)) { copyObj = copyObj[p] } } return copyObj }) atValues(object, paths)
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:
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 provided JSON and explain what's being tested, compared, and analyzed. **Benchmark Definition** The `Script Preparation Code` section defines the JavaScript object used for the benchmark: ```javascript var object = { 'a': [{ 'b': { 'c': 3 } }, 4] } ``` This object has two properties: an array of objects with a nested structure, and a primitive value (number). **Comparison** The benchmark compares two approaches: 1. **Lodash**: Uses the `at` function from the Lodash library (`lodash.js`) to access nested properties. 2. **Native**: Implements the `at` functionality manually using a loop and recursion. **Pros and Cons of each approach:** * **Lodash (Library)**: + Pros: - Faster execution times due to optimized C++ code - Easier to read and maintain, as it abstracts away low-level details + Cons: - Requires an additional library download and setup - May introduce overhead due to dependency management * **Native**: + Pros: - Faster execution times since it doesn't rely on external libraries - More control over the implementation, as it can be optimized for specific use cases + Cons: - More complex and harder to read, as it involves manual recursion and iteration - May require more development time and expertise **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for data manipulation, string utilities, and more. In this benchmark, the `at` function is used to access nested properties in objects. The `at` function takes two arguments: an object and a path (a string representing the nested property structure). It returns the value at the specified path. **Special JS feature/Syntax** There are no special JavaScript features or syntaxes mentioned in this benchmark. **Other Alternatives** If you want to explore alternative libraries or implementations for accessing nested properties, some options include: * **Underscore.js**: Similar to Lodash, but with a slightly different API. * **ES6 Object Accessors**: You can use the new `at` method on objects in modern JavaScript (ECMAScript 2019+), which provides a more concise way of accessing nested properties. * **Manual implementation**: If you're comfortable with manual recursion and iteration, you can implement your own `at` function using a loop and recursion. Please let me know if this explanation helps!
Related benchmarks:
_.get vs nativefeaf
ES6 Optional Chaining vs TS Optional Chaining result in javascript vs vs. Lodash _.get
Array immutable union: lodash union vs flatten and creating a new set
Array Map Vs Lodash Map (1)
Comments
Confirm delete:
Do you really want to delete benchmark?