当benchmark.js运行一个基准测试并向我展示最快的测试时,我尝试了它,但是我不知道如何从它中得到一个很好的报告--我尝试了如下:
suite.add('My#test', function() {
console.log("test")
}).on('complete', function() {
console.log('Fastest is ' + this.filter('fastest').map('name'));
console.log('stats: ' + suite.stats) // but stats seems undefined, do i miss anything? how come I couldn't find a guide on showing how to print stats?
}).run({ 'async': true });统计数据似乎没有定义,我有遗漏什么吗?为什么我找不到如何打印数据的指南?我如何得到一份报告,显示我要为每个测试方法运行测试所需的时间、中位数、错误数以及所有这些汇总?谢谢。
发布于 2017-01-21 08:45:40
你应该使用this
// add listeners
suite.on('cycle', function(event) {
console.log(String(event.target));
console.log(event.target.name);
console.log(event.target.stats.rme);
console.log(event.target.stats.sample.length);
console.log(event.target.count); // The number of times a test was executed.
console.log(event.target.cycles); // The number of cycles performed while benchmarking.
console.log(event.target.hz); //The number of executions per second.
})
.on('complete', function() {
for (var i = 0; i < this.length; i++) {
console.log(this[i].hz + " ops/sec");
console.log(this[i].stats.sample.length);
//console.log(this[i].stats);
}
console.log(color('Fastest is ' + this.filter('fastest').map('name'),'green'));
console.log(color('Slowest is ' + this.filter('slowest').map('name'),'red'));
})
// run async
.run({ 'async': true });https://stackoverflow.com/questions/40625644
复制相似问题