HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.28.0/ramda.min.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.min.js"></script>
Script Preparation code:
x
 
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:
  • JS native

     
    var result = data
      .map(({counter}) => counter)
      .filter(isOdd)
      .map(square)
      .filter(lessThanThreeDigits)
  • Ramda with transducer

     
    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,
    );
  • Ramda with transducer (no prop)

     
    var transducer = R.compose (
      R.map(({counter}) => counter),
      R.filter(isOdd),
      R.map(square),
      R.filter(lessThanThreeDigits),
    );
    var result = R.transduce (
      transducer,
      (acc, val) => {
        acc.push(val);
        return acc;
      },
      [],
      data,
    );
  • Ramda with currying and composition

     
    var result = R.pipe(
      R.pluck('counter'),
      R.filter(isOdd),
      R.map(square),
      R.filter(lessThanThreeDigits)
    )(data);
  • 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 (no pluck)

     
    var result = R.pipe(
      R.map (({counter}) => counter),
      R.filter(isOdd),
      R.map(square),
      R.filter(lessThanThreeDigits)
    )(data);
  • Lodash

     
    var result = _.chain(data)
      .map('counter')
      .filter(isOdd)
      .map(square)
      .filter(lessThanThreeDigits)
      .value();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    JS native
    Ramda with transducer
    Ramda with transducer (no prop)
    Ramda with currying and composition
    Ramda without relying on currying or composition
    Ramda with currying and composition (no pluck)
    Lodash

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (X11; Linux x86_64; rv:106.0) Gecko/20100101 Firefox/106.0
Firefox 106 on Linux
View result in a separate tab
Test name Executions per second
JS native 94.9 Ops/sec
Ramda with transducer 29.0 Ops/sec
Ramda with transducer (no prop) 85.5 Ops/sec
Ramda with currying and composition 28.8 Ops/sec
Ramda without relying on currying or composition 28.4 Ops/sec
Ramda with currying and composition (no pluck) 92.2 Ops/sec
Lodash 90.0 Ops/sec