lazy

JavaScript performance comparison

Revision 7 of this test case created by tomByrer

Info

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

Preparation code

<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>
<script>
Benchmark.prototype.setup = function() {
    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();
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
underscore
var result = _.chain(array).map(square).map(inc).filter(isEven).value();
pending…
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);
  }
}
pending…
lazy
var result = Lazy(array).map(square).map(inc).filter(isEven).toArray();
pending…
lodash
var result = lodash(array).map(square).map(inc).filter(isEven).value();
pending…
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;
  }
}
pending…
underscore 2
var result = _.filter(_.map(_.map(array, square), inc), isEven);
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. Here’s a list of current revisions for this page:

2 comments

tomByrer (revision owner) commented :

Ran to test against http://jsperf.com/chain-vs-pipe/6 Same i7 laptop results:

UserAgent  lazy  lodash  underscore  underscore 2  loop  optimized loop  # Tests

Chrome 31.0.1650 8,936 12,602 3,659 3,661 99,044 93,861 2

IE 10.0 12,238 13,202 10,077 10,257 47,375 62,842 2

Pale Moon (Firefox Variant) 24.2.2 3,932 6,713 1,337 1,397 39,591 54,102 5

tomByrer (revision owner) commented :

The first 2 tests for IE8 were run inside VituralBox. I doubt the numbers are super accurate, but they do follow the other browsers' trends.

IE 8.0 159 364 117 119 972 1,615 2

Add a comment