Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash reduce vs native (testing)
(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) console.log('a')
Lodash reduce
//_.reduce(numbers, (sum, n) => sum + n, 0) console.log('b')
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:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.2 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native reduce
1361607.1 Ops/sec
Lodash reduce
1268212.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested, compared, and what are the pros and cons of each approach. **What is being tested?** The benchmark compares two JavaScript functions: the native `reduce` function and the Lodash `_.reduce` function. Both functions perform a reduction operation on an array of numbers, adding up all the elements and logging the result to the console. **Options compared:** 1. **Native `reduce` function**: This is a built-in JavaScript function that reduces an array by applying a callback function to each element. 2. **Lodash `_.reduce` function**: This is a utility function provided by the Lodash library, which provides a more concise and readable way to perform reductions. **Pros and cons of each approach:** 1. **Native `reduce` function**: * Pros: + Built-in function, so no additional dependencies needed. + Typically faster than a custom implementation since it's optimized for performance. * Cons: + Can be less readable and more difficult to understand due to its concise syntax. + May require additional setup or preparation code (like in the benchmark). 2. **Lodash `_.reduce` function**: * Pros: + More readable and maintainable than the native `reduce` function, as it uses a more explicit syntax. + Often preferred by developers due to its familiarity and ease of use. * Cons: + Requires an additional dependency (the Lodash library). + May have performance overhead compared to the native `reduce` function. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like string manipulation, array manipulation, and more. The `_.reduce` function is one of these utility functions, which simplifies the reduction operation by providing a concise syntax and handling edge cases. **Special JS feature or syntax: None** This benchmark does not use any special JavaScript features or syntax that would affect its performance or behavior. **Other alternatives:** If you wanted to compare other implementations, you could consider: 1. **Array.prototype.reduce()**: This is another built-in JavaScript function that can be used for reductions. 2. **Custom implementation using loops**: You could write a custom loop-based implementation to perform the reduction operation. 3. **Other libraries or frameworks**: Depending on your specific use case, other libraries like Moment.js (for date manipulation) or jQuery (for DOM manipulation) might be relevant. Keep in mind that each alternative would require its own benchmarking and analysis to ensure fair comparisons.
Related benchmarks:
Lodash reduce vs native
Lodash reduce vs native in for loop
lodash reduce vs native reduce
lodash reduce vs array reduce
Comments
Confirm delete:
Do you really want to delete benchmark?