<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var fp = _.noConflict();
var data = _.range(10000).map(function(i) {
return {counter: i}
});
function isOdd(num) {
return num % 2 === 1;
}
var result = _.filter(data, isOdd);
var result = R.filter(isOdd, data);
var result = data.filter(({counter}) => isOdd(counter));
var result = _.find(data, {counter: 859});
var result = R.find(R.propEq('counter', 859), data);
var result = data.find(({counter}) => counter === 859);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash filter | |
Ramda filter | |
Native filter | |
Lodash find | |
Ramda find | |
Native find |
Test name | Executions per second |
---|---|
Lodash filter | 479.6 Ops/sec |
Ramda filter | 504.2 Ops/sec |
Native filter | 23965.3 Ops/sec |
Lodash find | 304227.8 Ops/sec |
Ramda find | 10215.0 Ops/sec |
Native find | 1608505.6 Ops/sec |
Let's break down the provided JSON and explain what's being tested.
Benchmark Overview
The benchmark compares the performance of three different libraries: Lodash, Ramda, and the native JavaScript implementation (without any external library). The focus is on two specific operations:
isOdd
).counter
).Library Overview
filter()
and find()
methods, which are built-in functions in the language.Comparison Options
The benchmark compares the performance of each library on the same tasks:
isOdd
):filter()
function.filter()
function.filter()
method.counter
):find()
function.find()
function.find()
method.Pros and Cons
Here's a brief summary of the pros and cons for each library:
Other Considerations
When choosing between these options, consider the following factors:
Alternatives
If you're looking for alternative libraries or approaches, consider the following:
Keep in mind that the choice of library ultimately depends on your project's specific needs, your personal preferences, and your team's expertise.