fix(benchpress): only print the CV when it is meaningful
When the mean is 0, the coefficient of variation is calculated to be NaN, which is not meaningful, so instead of printing "+-NaN%", just don't print the CV at all. Closes #908 Closes #1444
This commit is contained in:
parent
4650d25a53
commit
642e7e5c46
|
@ -83,10 +83,10 @@ export class ConsoleReporter extends Reporter {
|
|||
var sample = ListWrapper.map(validSample, (measureValues) => measureValues.values[metricName]);
|
||||
var mean = Statistic.calculateMean(sample);
|
||||
var cv = Statistic.calculateCoefficientOfVariation(sample, mean);
|
||||
var formattedCv = NumberWrapper.isNaN(cv) ? 'NaN' : Math.floor(cv);
|
||||
var formattedMean = ConsoleReporter._formatNum(mean)
|
||||
// Note: Don't use the unicode character for +- as it might cause
|
||||
// hickups consoles...
|
||||
return `${ConsoleReporter._formatNum(mean)}+-${formattedCv}%`;
|
||||
// hickups for consoles...
|
||||
return NumberWrapper.isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`;
|
||||
})
|
||||
);
|
||||
return PromiseWrapper.resolve(null);
|
||||
|
|
|
@ -96,6 +96,22 @@ export function main() {
|
|||
]);
|
||||
});
|
||||
|
||||
it('should print the coefficient of variation only when it is meaningful', () => {
|
||||
createReporter({
|
||||
columnWidth: 8,
|
||||
metrics: { 'a': '', 'b': '' }
|
||||
});
|
||||
log = [];
|
||||
reporter.reportSample([], [
|
||||
mv(0, 0, { 'a': 3, 'b': 0 }),
|
||||
mv(1, 1, { 'a': 5, 'b': 0 })
|
||||
]);
|
||||
expect(log).toEqual([
|
||||
'======== | ========',
|
||||
'4.00+-25% | 0.00'
|
||||
]);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue