jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Test performance of native filter method for arrays vs lodash filter method
<script src="//cdn.rawgit.com/lodash/lodash/54644cda79c7074ff710c73ecab7a8a91d583414/dist/lodash.js"></script>
var List = function (value) {
this.value = value || [];
};
List.prototype.unit = function (value) {
return new List(value);
};
List.prototype.flatMap = function (fn, context) {
var results = [];
this.value.forEach(function (value, key, map) {
var ret = fn.call(context, value, key, map);
if (ret instanceof List) {
ret = ret.get();
}
if (Array.isArray(ret)) {
[].push.apply(results, ret);
}
else if (ret) {
results.push(ret);
}
});
return new List(results);
};
List.prototype.get = function () {
return this.value;
};
List.prototype.map = function (fn) {
return this.flatMap(function (x) {
return this.unit(fn(x));
}, this);
};
List.prototype.filter = function (fn) {
return this.flatMap(function (x) {
return fn(x) ? this.unit(x) : null;
}, this);
};
List.prototype.filterNot = function (fn) {
return this.flatMap(function (x) {
return fn(x) ? null : this.unit(x);
}, this);
};
var a1 = _.range(100);
var a2 = _.union.apply(_, _.times(34, function() {
return [
{ name: 'john', age: 47 },
{ name: 'jane', age: 22 },
{ name: 'bill', age: 60 }
];
}));
Ready to run.
Test | Ops/sec | |
---|---|---|
lodash filter |
| ready |
Array.filter |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.