Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Ramda vs Underscore 1.9.0 vs native
(version: 2)
Comparing performance of:
Lodash vs Ramda without relying on currying or composition vs Ramda with currying and composition vs Underscore vs Native
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script> <script type="text/javascript"> window.lodash = _; _ = null; </script> <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.0/underscore.js"></script>
Script Preparation code:
var data = _.range(100000).map(function(i) { return { counter: i } }); function isOdd(num) { return num % 2 === 1; } function square(num) { return num * num; } function lessThanThreeDigits(num) { return num.toString().length < 3; }
Tests:
Lodash
var result = lodash.chain(data) .map(item => item.counter) .filter(isOdd) .map(square) .filter(lessThanThreeDigits) .value();
Ramda without relying on currying or composition
var result = R.filter(lessThanThreeDigits, R.map(square, R.filter(isOdd, R.pluck('counter', data))));
Ramda with currying and composition
var result = R.pipe( R.pluck('counter'), R.filter(isOdd), R.map(square), R.filter(lessThanThreeDigits) )(data);
Underscore
var result = _.chain(data) .map(item => item.counter) .filter(isOdd) .map(square) .filter(lessThanThreeDigits) .value();
Native
var result = data .map(item => item.counter) .filter(isOdd) .map(square) .filter(lessThanThreeDigits)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Lodash
Ramda without relying on currying or composition
Ramda with currying and composition
Underscore
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):
**Benchmark Explanation** The provided benchmark compares the performance of four different libraries: Lodash, Ramda, Underscore, and native JavaScript (without any library). **Libraries and Their Purposes** 1. **Lodash**: A popular utility library for functional programming in JavaScript. It provides a wide range of functions for tasks such as array manipulation, string formatting, and more. 2. **Ramda**: A functional programming library that builds on top of Lodash's API. It provides a set of higher-order functions to compose and manipulate data. 3. **Underscore**: Another popular utility library for functional programming in JavaScript. It provides a smaller set of functions compared to Lodash, but is still widely used. **Benchmark Test Cases** Each test case uses one of the libraries or native JavaScript to perform the same operation: filtering an array of objects based on three conditions: * `isOdd`: checks if a number is odd * `square`: squares a number * `lessThanThreeDigits`: checks if a number has fewer than 3 digits The test cases use different approaches to achieve this: 1. **Lodash**: Uses the `chain()` method to create a pipeline of operations, which are then executed in order. 2. **Ramda**: Uses a combination of higher-order functions to compose and manipulate data. There are two test cases: * "Ramda without relying on currying or composition": uses the `filter()` function directly * "Ramda with currying and composition": uses the `pipe()` function to compose operations 3. **Underscore**: Uses the `chain()` method similar to Lodash, but with a smaller set of functions. 4. **Native JavaScript**: Does not use any library and achieves the same result using simple array manipulation. **Options Compared** The benchmark compares the performance of each library or native JavaScript approach in executing the test case. The results are measured by the number of executions per second. **Pros and Cons of Each Approach** 1. **Lodash**: Pros: * Widely used and well-maintained * Provides a wide range of functions for various tasks Cons: * Can be slower due to the pipeline approach 2. **Ramda**: Pros: * Provides higher-order functions for functional programming * Can lead to more concise code Cons: * Steeper learning curve due to its API 3. **Underscore**: Pros: * Smaller and more lightweight than Lodash or Ramda * Easy to learn and use Cons: * Limited set of functions compared to other libraries 4. **Native JavaScript**: Pros: * Fastest execution time * No additional library dependencies **Other Considerations** When choosing a library for functional programming, consider the following: * Learning curve: How much do you need to learn about the library's API and concepts? * Functionality: What specific functions or operations do you need to perform? * Performance: Are speed and efficiency critical in your application? Ultimately, the choice of library depends on your personal preference, project requirements, and the trade-offs between development time, maintenance costs, and performance.
Related benchmarks:
Lodash vs Ramda vs Underscore 1.9.0 - IE11 Compatible
Lodash vs Ramda vs Underscore 1.5.2
Ramda(0.27.0) vs. Lodash(4.17.20) vs Natice (filter, find)
Ramda vs lodash latest
Comments
Confirm delete:
Do you really want to delete benchmark?