chuhai
Version:
Test driven benchmarking.
73 lines (59 loc) • 1.72 kB
JavaScript
var StackUtils = require('stack-utils');
module.exports = function (suite) {
if (suite.name && suite.name.length !== 0) {
console.log('## ' + suite.name);
}
console.log('');
var errored = [];
suite.sort(function (b, a) {
return a.stats.mean + a.stats.moe > b.stats.mean + b.stats.moe ? -1 : 1;
}).each(function (b) {
var m = [String(b)];
if (b.error) {
errored.push(b);
m.push('*error*');
}
if (b.options.burn) {
m.push('*burn in*');
}
console.log(' ' + m.join(' '));
});
if (suite.length > 1) {
console.log('');
var fastest = suite.filter(function (d) {
return d.options.burn !== true;
}).filter('fastest').map('name').join(', ');
console.log('*Fastest is __' + fastest + '__*');
}
console.log('');
if (errored.length > 0) {
errored.forEach(function (b, i) {
if (b.error.stack.indexOf('From previous event') > -1) {
// skip errors already caught by ava
return;
}
console.log('```');
console.log(i + 1 + '. ' + String(b) + ' ' + prettyStack(b.error.stack));
console.log('```');
console.error('');
});
}
};
var chuhaiInternals = /\/chuhai\/dist\//;
var chuhaiDependencies = /\/node_modules\/(?:bluebird|benchmark|lodash)\//;
var stackUtils = new StackUtils({
cwd: process.cwd(),
internals: [chuhaiInternals, chuhaiDependencies] });
function prettyStack(stack) {
if (!stack) {
return '';
}
var title = stack.split('\n')[0];
var lines = stackUtils.clean(stack).split('\n').filter(function (s) {
return s.length > 0;
}).map(function (s) {
return ' at ' + s;
}).join('\n');
return title + '\n' + lines;
}
;