Lazy-Lodash-Underscore (v3)

Revision 3 of this benchmark created on


Description

How Lazy.js compares to Underscore/Lodash

Preparation HTML

<script src="//rawgithub.com/dtao/lazy.js/master/lazy.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
<script>var underscore = _.noConflict();</script>
<script src="//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)
  }
}, 500000).toArray();

function filter1(x) {
  return x.a.toLowerCase().startsWith("f");
}

function filter2(x) {
  return x.b.toLowerCase().startsWith("f");
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Lazy (filter all records)
Lazy(data)
  .filter(filter1)
  .filter(filter2)
  .toArray();
ready
Lazy (the first 10 records)
Lazy(data)
  .filter(filter1)
  .filter(filter2)
  .take(10)
  .toArray();
ready
Lodash
lodash(data)
  .filter(filter1)
  .filter(filter2)
  .value()
ready
Underscore
underscore.chain(data)
  .filter(filter1)
  .filter(filter2)
  .value()
ready

Revisions

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