Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs Ramda vs Native 2022-11-23
(version: 3)
Tests libraries lodash, ramda and native array functions on a sequence of map, filter, map filter operations.
Comparing performance of:
Lodash vs Ramda without relying on currying or composition vs Ramda with currying and composition vs Native
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js" integrity="sha512-rZHvUXcc1zWKsxm7rJ8lVQuIr1oOmm7cShlvpV0gWf0RvbcJN6x96al/Rp2L2BI4a4ZkT2/YfVe/8YvB2UHzQw==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js" integrity="sha512-90vH1Z83AJY9DmlWa8WkjkV79yfS2n2Oxhsi2dZbIv0nC4E6m5AbH8Nh156kkM7JePmqD6tcZsfad1ueoaovww==" crossorigin="anonymous"></script>
Script Preparation code:
var data = _.range(100000000).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 = _.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);
Native
var result = data .map(x => x.counter) .filter(isOdd) .map(square) .filter(lessThanThreeDigits) ;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Lodash
Ramda without relying on currying or composition
Ramda with currying and composition
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):
Measuring the performance of JavaScript libraries can be a complex task, but I'll break it down for you. **Benchmark Overview** The benchmark tests four approaches to perform a series of operations on an array: 1. **Lodash**: Uses the `lodash` library to chain together methods like `map`, `filter`, and others. 2. **Ramda without currying or composition**: Uses the `ramda` library, but with a twist - it avoids using currying (a technique where a function is called with an argument that is another function) and composition (applying functions in sequence). This approach tries to replicate the behavior of Lodash. 3. **Ramda with currying and composition**: Uses the `ramda` library, this time using its full capabilities, including currying and composition. This approach aims to show the benefits of using a functional programming library like Ramda. 4. **Native**: Performs the operations directly in JavaScript, without relying on any libraries. **Library Overview** * **Lodash**: A popular utility library that provides a wide range of functions for tasks like array manipulation, string manipulation, and more. Its `chain` method is particularly useful for chaining together multiple operations. * **Ramda**: Another functional programming library that aims to provide a more concise and expressive way of working with data. It has a strong focus on composition and currying. **Options Compared** The benchmark compares the performance of these four approaches: 1. **Lodash** vs. **Native**: This comparison tests the overhead of using an external library like Lodash compared to performing operations directly in JavaScript. 2. **Ramda without currying or composition** vs. **Ramda with currying and composition**: This comparison highlights the benefits of using a functional programming library like Ramda, particularly when using its full capabilities. **Pros and Cons** * **Lodash**: + Pros: Easy to use, extensive set of functions for common tasks. + Cons: Adds overhead due to external library, may not be as performant as native JavaScript code. * **Ramda without currying or composition**: + Pros: Avoids some of the complexity and abstraction of using Ramda with currying and composition. + Cons: May not be as expressive or concise as using Ramda with its full capabilities. * **Ramda with currying and composition**: + Pros: Leverages the full power of Ramda, allowing for more expressive and concise code. + Cons: Can be overwhelming for beginners, may require more time to learn. **Other Considerations** * **Currying**: In functional programming, a function is called with an argument that is another function. This approach can simplify certain operations, but may also add overhead. * **Composition**: In functional programming, functions are applied in sequence to create new functions. Ramda uses this concept extensively. **Alternatives** If you're looking for alternatives to Lodash and Ramda, consider: * **Built-in JavaScript methods**: Many array and string manipulation operations have built-in equivalents in JavaScript. * **Other libraries**: Other utility libraries like `underscore` or `fp.js` may offer similar functionality to Lodash and Ramda. Please note that the performance differences between these approaches can vary depending on the specific use case, data size, and hardware.
Related benchmarks:
Ramda vs. Lodash 3
Ramda vs. Lodash updated
Ramda vs. Lodash updated again
Ramda vs. Lodash 2021
Ramda vs. Lodash 2021 v2
Comments
Confirm delete:
Do you really want to delete benchmark?