lazy

JavaScript performance comparison

Revision 2 of this test case created by P

Info

Tweaking vanilla test, and others.

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(),
        length = array.length,
        value, result, i, results = [];
};
</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
result = _.chain(array).map(square).map(inc).filter(isEven).take(5).value();
pending…
loop
for (i = 0; i < length; ++i) {
  value = ((array[i] * array[i]) + 1) % 2;
  if (!value) {
    if (results.push(value) === 5) {
      break;
    }
  }
}
pending…
lazy
result = Lazy(array).map(square).map(inc).filter(isEven).take(5).toArray();
pending…
lodash
result = lodash(array).map(square).map(inc).filter(isEven).take(5).value();
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

P (revision owner) commented :

Wow I thought I was improving things... did I do something wrong?

Calvin commented :

your only pushing 0 or 1 into the array for one, I also have a feeling doing the push inside the if is what's slowing you down

Add a comment