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
Provide pipe as an alternative to chain.
Pros:
Cons:
For what it's worth it employs pointfree style which is preferred for reasons of its own. http://www.haskell.org/haskellwiki/Pointfree
v6: updated libs
<script src='//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore.js'></script>
<script src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.4.0/lodash.js'></script>
<script src='//rawgithub.com/dtao/lazy.js/master/lazy.js'></script>
<script>
var lodash = _.noConflict();
function pipe(seed){
var seeded = arguments.length > 0, composed = [];
return function piping(verb){
if (arguments.length === 0) {
var fn = _.compose.apply(null, composed);
return seeded ? fn(seed) : fn;
}
var args = _.rest(arguments);
composed.unshift(function(obj){
return verb.apply(null, [obj].concat(args));
});
return piping;
}
};
_.pipe = pipe;
</script>
var _ = window._,
lodash = window.lodash,
lyrics = [],
index = 0;
_.times(25, function() {
lyrics.push(
{line : index++, words : "I'm a lumberjack and I'm okay"},
{line : index++, words : "I sleep all night and I work all day"},
{line : index++, words : "He's a lumberjack and he's okay"},
{line : index++, words : "He sleeps all night and he works all day"},
{line : index++, words : "http://www.youtube.com/watch?v=mL7n5mEmXJo"}
);
});
var chainCounter = function(collection) {
return _(collection)
.chain()
.map(function(line) { return line.words.split(' '); })
.flatten()
.filter(function(word) { return !/[aio]/i.test(word); })
.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {})
.value();
};
var lodashChainCounter = function(collection) {
return lodash(collection)
.chain()
.map(function(line) { return line.words.split(' '); })
.flatten()
.filter(function(word) { return !/[aio]/i.test(word); })
.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {})
.value();
};
var genericCounter = function(collection) {
var result = _.map(collection, function(line) {
return line.words.split(' ');
});
result = _.flatten(result);
result = _.filter(result, function(word) {
return !/[aio]/i.test(word);
});
return _.reduce(result, function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {});
};
var lodashGenericCounter = function(collection) {
var result = lodash.map(collection, function(line) {
return line.words.split(' ');
});
result = lodash.flatten(result);
result = lodash.filter(result, function(word) {
return !/[aio]/i.test(word);
});
return lodash.reduce(result, function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {});
};
var pipeCounter = _.pipe()
(_.map, function(line) { return line.words.split(' '); })
(_.flatten)
(_.filter, function(word) { return !/[aio]/i.test(word); })
(_.reduce, function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {})
();
var lazyCounter = function(collection) {
return Lazy(collection)
.map(function(line) { return line.words.split(' '); })
.flatten()
.filter(function(word) { return !/[aio]/i.test(word); })
.reduce(function(counts, word) {
counts[word] = (counts[word] || 0) + 1;
return counts;
}, {});
};
Ready to run.
Test | Ops/sec | |
---|---|---|
Chain |
| ready |
Pipe |
| ready |
Generic |
| ready |
Lazy |
| ready |
Lo-Dash chain |
| ready |
Lo-Dash generic |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.