Skip to content

Commit 642e7e5

Browse files
srawlinsmhevery
authored andcommitted
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 angular#908 Closes angular#1444
1 parent 4650d25 commit 642e7e5

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

modules/benchpress/src/reporter/console_reporter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ export class ConsoleReporter extends Reporter {
8383
var sample = ListWrapper.map(validSample, (measureValues) => measureValues.values[metricName]);
8484
var mean = Statistic.calculateMean(sample);
8585
var cv = Statistic.calculateCoefficientOfVariation(sample, mean);
86-
var formattedCv = NumberWrapper.isNaN(cv) ? 'NaN' : Math.floor(cv);
86+
var formattedMean = ConsoleReporter._formatNum(mean)
8787
// Note: Don't use the unicode character for +- as it might cause
88-
// hickups consoles...
89-
return `${ConsoleReporter._formatNum(mean)}+-${formattedCv}%`;
88+
// hickups for consoles...
89+
return NumberWrapper.isNaN(cv) ? formattedMean : `${formattedMean}+-${Math.floor(cv)}%`;
9090
})
9191
);
9292
return PromiseWrapper.resolve(null);

modules/benchpress/test/reporter/console_reporter_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ export function main() {
9696
]);
9797
});
9898

99+
it('should print the coefficient of variation only when it is meaningful', () => {
100+
createReporter({
101+
columnWidth: 8,
102+
metrics: { 'a': '', 'b': '' }
103+
});
104+
log = [];
105+
reporter.reportSample([], [
106+
mv(0, 0, { 'a': 3, 'b': 0 }),
107+
mv(1, 1, { 'a': 5, 'b': 0 })
108+
]);
109+
expect(log).toEqual([
110+
'======== | ========',
111+
'4.00+-25% | 0.00'
112+
]);
113+
});
114+
99115
});
100116
}
101117

0 commit comments

Comments
 (0)