dockerfile/examples/omnivore/api/readabilityjs/benchmarks/benchmark-reporter.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-03-15 14:52:38 +08:00
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(benchResults) {
currentResults.push(benchResults.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);
};