Lazy-Lodash-Underscore

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code

<script src="https://rawgithub.com/dtao/lazy.js/master/lazy.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>var lodash = _.noConflict();</script>
<script>
var data = Lazy.generate(function() {
  return {
    a: Math.random().toString(36).substring(7),
    b: Math.random().toString(36).substring(7),
    c: Math.random().toString(36).substring(7),
    d: Math.random().toString(36).substring(7),
    e: Math.random().toString(36).substring(7),
    f: Math.random().toString(36).substring(7),
    g: Math.random().toString(36).substring(7),
    h: Math.random().toString(36).substring(7),
    i: Math.random().toString(36).substring(7),
    j: Math.random().toString(36).substring(7),
    k: Math.random().toString(36).substring(7),
    l: Math.random().toString(36).substring(7),
    m: Math.random().toString(36).substring(7),
    n: Math.random().toString(36).substring(7)
  }
}, 25000).toArray();
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var _ = window._,
      Lazy = window.Lazy,
      lodash = window.lodash;
  
  var data = window.data;
  
  function filter1(x) {
    return x.a.toLowerCase().charAt(0) == "f";
  }
  
  function filter2(x) {
    return x.b.toLowerCase().charAt(0) == "a";
  }

};
</script>

Preparation code output

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script> <script>var lodash = _.noConflict();</script> <script> var data = Lazy.generate(function() { return { a: Math.random().toString(36).substring(7), b: Math.random().toString(36).substring(7), c: Math.random().toString(36).substring(7), d: Math.random().toString(36).substring(7), e: Math.random().toString(36).substring(7), f: Math.random().toString(36).substring(7), g: Math.random().toString(36).substring(7), h: Math.random().toString(36).substring(7), i: Math.random().toString(36).substring(7), j: Math.random().toString(36).substring(7), k: Math.random().toString(36).substring(7), l: Math.random().toString(36).substring(7), m: Math.random().toString(36).substring(7), n: Math.random().toString(36).substring(7) } }, 25000).toArray(); </script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Lazy (filter all records)
Lazy(data)
  .filter(filter1)
  .filter(filter2)
  .toArray();
pending…
Lazy (the first 5 records)
Lazy(data)
  .filter(filter1)
  .filter(filter2)
  .take(5)
  .toArray();
pending…
Lodash
lodash(data)
  .filter(filter1)
  .filter(filter2)
  .value()
pending…
Underscore
_.chain(data)
  .filter(filter1)
  .filter(filter2)
  .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.

0 Comments