Add benchmark for readability itself instead of just JSDOMParser, add averages so the results are scannable.
parent
e51457d787
commit
02b7db3f7e
@ -0,0 +1,41 @@
|
||||
var matchaPath = require.resolve('matcha');
|
||||
var path = require('path');
|
||||
|
||||
var clean = require('matcha/lib/matcha/reporters/clean'));
|
||||
|
||||
function average(list) {
|
||||
if (!list.length)
|
||||
return 0;
|
||||
|
||||
var sum = list.reduce(function(previous, current) { return previous + current; });
|
||||
return (sum / list.length).toFixed(0);
|
||||
}
|
||||
|
||||
|
||||
// Like clean, but also produces an average:
|
||||
module.exports = function(runner, utils) {
|
||||
var humanize = utils.humanize;
|
||||
var padBefore = utils.padBefore;
|
||||
var color = utils.color;
|
||||
var results = {};
|
||||
var currentResults = [];
|
||||
runner.on('bench end', function(results) {
|
||||
currentResults.push(results.ops);
|
||||
});
|
||||
runner.on('suite end', function(suite) {
|
||||
var avg = humanize(average(currentResults));
|
||||
console.log(padBefore(avg + ' op/s', 22) + ' » ' + suite.title);
|
||||
console.log();
|
||||
results[suite.title] = avg;
|
||||
currentResults = [];
|
||||
});
|
||||
|
||||
runner.on('end', function() {
|
||||
for (var k in results) {
|
||||
console.log(color(padBefore(k, 30) + ': ', 'gray') + results[k] + ' op/s');
|
||||
}
|
||||
console.log();
|
||||
});
|
||||
|
||||
clean(runner, utils);
|
||||
};
|
Loading…
Reference in New Issue