lodash-lazy-lx

JavaScript performance comparison

Revision 9 of this test case created by Tom Smeding

Preparation code

<script src="https://cdn.rawgit.com/dtao/lazy.js/7a9b0210d97168ff48c5d2b4ce4d12194ba7fbec/lazy.js"></script>
<script src="https://cdn.rawgit.com/Reactive-Extensions/IxJS/es6/dist/ix.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore.js"></script>
<script src="https://cdn.rawgit.com/lodash/lodash/55df525f1bd3c6407de96fb275503bd1109fd259/lodash.js"></script>
<script>var lodash = _.noConflict();</script>

<script>
Benchmark.prototype.setup = function() {
var arr = _.range(10000),
limit = 9000;

var odd = function(v) {return !!(v % 2);},
square = function(v) {return v * v;};

};
</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
Native
var r = arr.map(square).filter(odd).slice(0, limit);
pending…
Underscore
var r = _(arr).chain().map(square).filter(odd).take(limit).value();
pending…
Ix
var r = Ix.Enumerable.from(arr).map(square).filter(odd).take(limit).toArray();
pending…
Lazy
var r = Lazy(arr).map(square).filter(odd).take(limit).toArray();
pending…
Lo-Dash
var r = lodash(arr).map(square).filter(odd).take(limit).value();
pending…
Real fast native
var r = [], arrlen = arr.length;
for (var i = 0; i < arrlen && r.length < limit; i++) {
m = square(arr[i]);
if (odd(m)) r.push(m);
}
pending…
Real fast native with pre-allocation
var arrlen = arr.length, r = new Array(arrlen), ridx = 0;
for (var i = 0; i < arrlen && r.length < limit; i++) {
m = square(arr[i]);
if (odd(m)) r[ridx++] = m;
}
r = r.slice(0, ridx);
pending…

Revisions

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