Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash reduce vs native
(version: 0)
This test aims to compare lodash reduce function with the Javascript native reduce function, doing exactly the same operation
Comparing performance of:
Native reduce vs Lodash reduce
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 nbLength = 100000000 //100M var numbers = []; for (var i = 0; i <= nbLength; i++) { numbers.push(i); }
Tests:
Native reduce
numbers.reduce((sum, n) => sum + n, 0)
Lodash reduce
_.reduce(numbers, (sum, n) => sum + n, 0)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native reduce
Lodash reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0
Browser/OS:
Firefox 136 on Ubuntu
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native reduce
2.2 Ops/sec
Lodash reduce
2.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** The provided benchmark tests the performance of two approaches to perform a reduction operation on an array: the native JavaScript `reduce` function and the Lodash `reduce` function. **Options compared** The two options being compared are: 1. **Native JavaScript `reduce` function**: This is a built-in function in JavaScript that applies a specified reduction function to each element of an array, accumulating a single value. 2. **Lodash `reduce` function**: This is a utility function provided by the Lodash library that performs the same operation as the native `reduce` function. **Pros and Cons** * **Native JavaScript `reduce` function**: + Pros: Built-in, efficient, and lightweight. + Cons: May not be as readable or maintainable as alternative implementations, especially for complex operations. * **Lodash `reduce` function**: + Pros: Well-documented, tested, and widely adopted. Provides additional features and options that may improve readability and maintainability. + Cons: Requires an external library, which adds overhead. May not be suitable for all use cases or environments. **Other considerations** * **Library usage**: The test uses the Lodash library to provide the `reduce` function implementation. While this is a common approach in web development, it may not be suitable for all projects or environments where an external dependency is not desired. * **Special JS feature or syntax**: Neither of the compared implementations utilizes any special JavaScript features or syntax. **Alternatives** If you prefer to implement your own reduction operation without relying on a library, you can use the following alternatives: 1. **Array.prototype.reduce()**: This is the same function as the native `reduce` function in JavaScript. 2. **Manual iteration**: You can write a simple loop to iterate over the array and accumulate the results manually. Here's an example implementation using manual iteration: ```javascript const numbers = [1, 2, 3, 4, 5]; let sum = 0; for (const num of numbers) { sum += num; } console.log(sum); // Output: 15 ``` This approach is more verbose and less efficient than using the native `reduce` function or a library like Lodash.
Related benchmarks:
Lodash reduce vs native in for loop
lodash reduce vs native reduce
Lodash reduce vs native (testing)
lodash reduce vs array reduce
Comments
Confirm delete:
Do you really want to delete benchmark?