lazy

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

<script src="http://dtao.github.io/lazy.js/lazy.js">
</script>
<script src="http://dtao.github.io/lazy.js/docs/lib/underscore.js">
</script>
<script src="http://dtao.github.io/lazy.js/docs/lib/lodash.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).take(5).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);
    if (results.length === 5) {
      break;
    }
  }
}
pending…
lazy
var result = Lazy(array).map(square).map(inc).filter(isEven).take(5).toArray();
pending…
lodash
var result = lodash(array).map(square).map(inc).filter(isEven).take(5).value();
pending…
optimized loop
var len = array.length,
    outLen = 5,
    results = new Array(outLen),
    rlen = 0;
for (var i = 0; i < len; ++i) {
  var value = (array[i] * array[i]) + 1;
  if (value % 2 === 0) {
    results[rlen] = value;
    rlen++;
    if (rlen === outLen) {
      break;
    }
  }
}
pending…
closure compiled optimized loop
for(var len=array.length,outLen=5,results=Array(outLen),rlen=0,i=0;i<len;++i){var value=array[i]*array[i]+1;if(0===value%2&&(results[rlen]=value,rlen++,rlen===outLen))break};
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:

0 comments

Add a comment