Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Native reduce on object Copy
(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://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
Script Preparation code:
window.obj = {}; for (var i = 0, len = 10; i < len; i++) { var arr = [] obj['key' + i] = arr for (var n = 0, len = 10; n < len; n++) { arr.push({ ['key' + n]: n }); } }
Tests:
Lodash
_.reduce(obj, (acc, val) => { acc.push(val.map(d => ({ value: val }))); return acc; }, [])
Native
Object.values(obj).reduce((acc, val) => { acc.push(val.map(d => ({ value: val }))); return acc; }, [])
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
gemma2:9b
, generated one year ago):
This benchmark compares the performance of Lodash's `_.reduce()` function against JavaScript's native `reduce()` method when processing an object. **What is being tested?** The benchmark evaluates how efficiently each approach transforms a nested object structure. Both tests aim to create a new array from the original object, with each element in the resulting array containing transformed data from the nested objects within the original. * **Lodash Approach:** Uses `_.reduce()` to iterate over the values of the input object and apply a transformation function to each value. * **Native Approach:** Employs `Object.values()` to retrieve the values of the input object, followed by applying the native `reduce()` method for iteration and transformation. **Options Compared (Pros/Cons):** * **Lodash (`_.reduce`)**: * **Pro:** Well-established, often optimized for performance in common tasks. Offers additional features and convenience compared to native functions. * **Con:** Introduces a dependency on the Lodash library, potentially adding unnecessary size and overhead if other Lodash functionalities aren't used. * **Native `reduce()`**: * **Pro:** No external library dependency, keeping your code leaner and potentially faster in some cases. * **Con:** Might require more explicit code for common tasks compared to Lodash's more concise syntax. The performance might not always be as optimized as Lodash. **Other Considerations:** * **Benchmark Results**: In this specific case, the native `reduce()` method outperformed Lodash's `_.reduce()` by a significant margin. However, benchmark results can vary depending on factors like hardware, browser engine, and the specific code being executed. * **Readability:** While Lodash's syntax might appear more concise, it can sometimes be less readable for developers unfamiliar with Lodash's conventions. * **Ecosystem**: Lodash is a part of a vast JavaScript ecosystem with extensive documentation, community support, and numerous use cases. **Alternatives:** * **Functional Programming Libraries:** Consider libraries like Ramda or Immutable.js if you favor functional programming paradigms and need advanced array manipulation capabilities. * **Custom Implementation:** For very specific use cases, it might be worthwhile to write a highly optimized custom function tailored to your exact requirements.
Related benchmarks:
Lodash vs Native reduce on object - updated 2
Lodash vs Native reduce + Object.keys for collections
Lodash reduce vs transform vs Native reduce on object
Lodash reduce vs transform vs Native reduce on object (Object without prototype)
Comments
Confirm delete:
Do you really want to delete benchmark?