Test name | Executions per second |
---|---|
Lodash | 579239.2 Ops/sec |
Ramda with transducer | 1725.4 Ops/sec |
Ramda with currying and composition | 1875.9 Ops/sec |
Ramda without relying on currying or composition | 1867.7 Ops/sec |
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
var data = _.range(10000).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;
}
var result = _.chain(data)
.pick('counter')
.filter(isOdd)
.map(square)
.filter(lessThanThreeDigits)
.value();
var transducer = R.compose (
R.map(R.prop('counter')),
R.filter(isOdd),
R.map(square),
R.filter(lessThanThreeDigits),
);
var result = R.transduce (
transducer,
(acc, val) => {
acc.push(val);
return acc;
},
[],
data,
);
var result = R.pipe(
R.pluck('counter'),
R.filter(isOdd),
R.map(square),
R.filter(lessThanThreeDigits)
)(data);
var result = R.filter(lessThanThreeDigits,
R.map(square,
R.filter(isOdd,
R.pluck('counter', data))));