Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Chrome 132
Windows
Desktop
2 months ago
Test name Executions per second
Lodash funcional style (idiomatic) 2907.0 Ops/sec
Lodash functional style (performance optimized with spread) 5210.2 Ops/sec
Ramda without relying on currying or composition 880.6 Ops/sec
Ramda with currying and composition 864.6 Ops/sec
Ramda with transducers 759.1 Ops/sec
VanillaJS funcional style (idiomatic) 2703.3 Ops/sec
VanillaJS functional style (performance optimized with spread) 5908.4 Ops/sec
VanillaJS procedural 6313.7 Ops/sec
HTML Preparation code:
AخA
 
1
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.min.js"></script>
2
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js"></script>
Script Preparation code:
x
 
var data = [];
for (var i = 0; i < 10000; i++) {
     data.push({ counter: i });
}
function isOdd(num) {
  return num % 2 === 1;
}
function square(num) {
  return num * num;
}
function lessThanThreeDigits(num) {
  return num.toString().length < 3;
}
var expected = data.map(o => o.counter).filter(isOdd).map(square).filter(lessThanThreeDigits);
Tests:
  • Lodash funcional style (idiomatic)

     
    var result = _.chain(data)
      .map('counter')
      .filter(isOdd)
      .map(square)
      .filter(lessThanThreeDigits)
      .value();
  • Lodash functional style (performance optimized with spread)

     
    var result = _.reduce(data, function(acc, d) {
      var c = d.counter;
      return (isOdd(c) && lessThanThreeDigits(square(c))) 
        ? [...acc, square(c)] 
        : acc;
    }, []);
  • 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);
  • Ramda with transducers

     
    const xf = R.compose(
      R.map(R.prop('counter')),
      R.filter(isOdd),
      R.map(square),
      R.filter(lessThanThreeDigits)
    );
    const result = R.transduce(xf, R.flip(R.append), [], data);
  • VanillaJS funcional style (idiomatic)

     
    var result = data.map(o => o.counter).filter(isOdd).map(square).filter(lessThanThreeDigits);
  • VanillaJS functional style (performance optimized with spread)

     
    var result = data.reduce((acc, d) => {
      var c = d.counter;
      return (isOdd(c) && lessThanThreeDigits(square(c))) 
        ? [...acc, square(c)] 
        : acc;
    }, []);
  • VanillaJS procedural

     
    var result = new Array();
    for (var i = 0; i < data.length; i++) {
      var c = data[i].counter;
      if (isOdd(c)) {
        var r = square(c);
        if (lessThanThreeDigits(r)) {
          result.push(r);
        }
      }
    }