Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash reduce vs. native reduce
(version: 0)
Comparing performance of:
_.reduce vs native reduce
Created:
7 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 stuff = [ { name: 'pi', value: 3.14 }, { name: 'hundred', value: 100 }, { name: 'truthy', value: true }, { name: 'falsy', value: false }, { name: 'estring', value: '2.71828' }, ]
Tests:
_.reduce
_.reduce(stuff, (acc, item) => { acc[item.name] = item.value return acc }, {})
native reduce
stuff.reduce((acc, item) => { acc[item.name] = item.value return acc }, {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.reduce
native reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser/OS:
Firefox 139 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.reduce
5832862.0 Ops/sec
native reduce
2785918.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **Benchmark Overview** The provided benchmark measures the performance difference between Lodash's `reduce` function and the native `reduce` method in JavaScript. The test creates an array of objects (`stuff`) and uses both methods to accumulate values in an object, where each key is a property name from the input array. **Options Compared** The two options being compared are: 1. **Lodash's `_reduce` function**: This is a custom implementation of the `reduce` method using Lodash's utility functions. 2. **Native `reduce` method**: This is the built-in `reduce` method provided by JavaScript, which is implemented in the browser's engine (in this case, Chrome). **Pros and Cons** Here are some pros and cons of each approach: **Lodash's `_reduce` function:** Pros: * Provides a consistent API across different browsers and environments. * Includes additional features like memoization, which can improve performance. Cons: * Adds an extra layer of abstraction, potentially leading to overhead due to the library's functionality. * May not be optimized for specific use cases or edge cases. **Native `reduce` method:** Pros: * Optimized for native execution, with minimal overhead from additional libraries or functions. * Can take advantage of browser-specific optimizations and caching mechanisms. Cons: * Behavior can vary between browsers and versions, potentially leading to inconsistent results. * Limited control over implementation details, such as the order of operations or caching strategies. **Library (Lodash)** Lodash is a popular JavaScript utility library that provides a comprehensive set of functions for tasks like array manipulation, string trimming, and more. In this benchmark, Lodash's `reduce` function is used to implement the `_reduce` method, which allows for a consistent API across different browsers and environments. **Special JS Feature/Syntax** This benchmark does not use any special JavaScript features or syntax, so no additional explanations are needed. **Other Alternatives** For similar benchmarks, you might want to consider other options: * **Underscore.js**: Another popular utility library that provides a `reduce` function. * **Array.prototype.reduce()`: A built-in method in JavaScript that can be used as an alternative to Lodash's `_reduce` function. * **Other libraries or frameworks**: Depending on the specific use case, other libraries like Ramda, Immutable.js, or functional programming frameworks might provide optimized implementations of `reduce`. Keep in mind that each option has its trade-offs and potential performance implications. When choosing a library or implementation, consider factors like consistency, maintainability, and optimization for your specific requirements.
Related benchmarks:
Lodash reduce with native reduce
Lodash reduce vs native
lodash reduce vs native reduce
Lodash reduce vs native (testing)
Comments
Confirm delete:
Do you really want to delete benchmark?