Lazy-Lodash-Underscore

JavaScript performance comparison

Revision 3 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>var underscore = _.noConflict();</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)
  }
}, 500000).toArray();

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

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

Preparation code output

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script> <script>var underscore = _.noConflict();</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) } }, 500000).toArray(); function filter1(x) { return x.a.toLowerCase().startsWith("f"); } function filter2(x) { return x.b.toLowerCase().startsWith("f"); } </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
Underscore
underscore.chain(data)
  .filter(filter1)
  .filter(filter2)
  .value()
pending…
Lodash
lodash(data)
  .filter(filter1)
  .filter(filter2)
  .value()
pending…
Lazy (the first 10 records)
Lazy(data)
  .filter(filter1)
  .filter(filter2)
  .take(10)
  .toArray();
pending…
Lazy (filter all records)
Lazy(data)
  .filter(filter1)
  .filter(filter2)
  .toArray();
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