lazy (v7)

Revision 7 of this benchmark created by tomByrer on


Description

v7: new CDN versions, rawgithub for lazy.js.

Preparation HTML

<script src='//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js'></script>
<script src='//rawgithub.com/dtao/lazy.js/master/lazy.js'></script>
<script>
  window.lodash = _.noConflict();
</script>

Setup

function square(x) {
      return x * x;
    }
    
    function inc(x) {
      return x + 1;
    }
    
    function isEven(x) {
      return x % 2 === 0;
    }
    var array = Lazy.range(1000).toArray();

Test runner

Ready to run.

Testing in
TestOps/sec
underscore
var result = _.chain(array).map(square).map(inc).filter(isEven).value();
ready
loop
var results = [];
for (var i = 0; i < array.length; ++i) {
  var value = (array[i] * array[i]) + 1;
  if (value % 2 === 0) {
    results.push(value);
  }
}
ready
lazy
var result = Lazy(array).map(square).map(inc).filter(isEven).toArray();
ready
lodash
var result = lodash(array).map(square).map(inc).filter(isEven).value();
ready
optimized loop
var len = array.length,
    results = new Array(500),
    rlen = 0;
for (var i = 0; i < len; ++i) {
  var value = (array[i] * array[i]) + 1;
  if (value % 2 === 0) {
    results[rlen++] = value;
  }
}
ready
underscore 2
var result = _.filter(_.map(_.map(array, square), inc), isEven);
ready

Revisions

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