Ramda vs. Lodash

JavaScript performance comparison

Revision 12 of this test case created by John R. Cui

Preparation code

<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
      
<script>
Benchmark.prototype.setup = function() {
  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;
  }

};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Ramda with currying and composition
// Longer but more maintainable.
var result = R.pipe(
  R.filter(lessThanThreeDigits),
  R.map(square),
  R.filter(isOdd),
  R.pluck('counter')
)(data);
pending…
Native functional
var result = result = data
  .map(function(value) {
    return value.counter;
  })
  .filter(isOdd)
  .map(square)
  .filter(lessThanThreeDigits);
pending…
Lodash
var result = _.chain(data)
  .map('counter')
  .filter(isOdd)
  .map(square)
  .filter(lessThanThreeDigits)
  .value();
pending…
Ramda Into
var result = R.into(
  [],
  R.compose(
    R.filter(lessThanThreeDigits),
    R.map(square),
    R.filter(isOdd),
    R.pluck('counter')
  ), data);
pending…
Native imperative
var result = [];
var length = data.length;
for (var i = 0; i < data.length; i++) {
  var value = data[i].counter;
  var squared;
  if (isOdd(value)) {
    squared = square(value);
    if (lessThanThreeDigits(squared)) {
      result.push(squared);
    }
  }
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments