lazy-demo (v18)

Revision 18 of this benchmark created on


Preparation HTML

<script src="https://cdn.rawgit.com/lodash/lodash/4.0.0/lodash.js"></script>

Setup

var arr = _.range(10000),
      limit = 100;
    
    var odd = function(v) {
      return !!(v % 2);
    },
      square = function(v) {
        return v * v;
      };
    
    var rargs = function(fun) {
      return function() {
        var args = Array.prototype.slice.call(arguments).reverse();
        fun.apply(null, args);
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
regular
var r = _.take(_.filter(_.map(arr, square), odd), limit);
ready
lazy
var r = _(arr).map(square).filter(odd).take(limit).value();
ready
func
var r = _.compose(function(elems){ return _.take(elems, limit); }, function(elems){ return _.filter(elems, odd); }, _.map)(arr);
ready

Revisions

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