Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 447b8a6

Browse files
jeffbcrossjbdeboer
authored andcommitted
feat(benchmark): calculate coefficient of variation
1 parent e6c8563 commit 447b8a6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

benchmark/web/bp.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ bp.Statistics.calculateConfidenceInterval = function(standardDeviation, sampleSi
4343
return bp.Statistics.criticalValue * standardError;
4444
};
4545

46-
bp.Statistics.calculateRelativeMarginOfError = function (marginOfError, mean) {
46+
bp.Statistics.calculateRelativeMarginOfError = function(marginOfError, mean) {
4747
/*
4848
* Converts absolute margin of error to a relative margin of error by
4949
* converting it to a percentage of the mean.
5050
*/
5151
return (marginOfError / mean);
5252
};
5353

54+
bp.Statistics.calculateCoefficientOfVariation = function(standardDeviation, mean) {
55+
return standardDeviation / mean;
56+
};
57+
5458
bp.Statistics.calculateStandardDeviation = function(sample, mean) {
5559
var deviation = 0;
5660
sample.forEach(function(x) {
@@ -256,6 +260,7 @@ bp.Report.calcStats = function() {
256260
avg: avg,
257261
times: tpa.fmtTimes,
258262
timesStandardDeviation: timesStandardDeviation,
263+
coefficientOfVariation: bp.Statistics.calculateCoefficientOfVariation(timesStandardDeviation, avg.time),
259264
timesRelativeMarginOfError: bp.Statistics.calculateRelativeMarginOfError(timesConfidenceInterval, avg.time),
260265
gcTimes: tpa.fmtGcTimes,
261266
garbageTimes: tpa.fmtGarbageTimes,

benchmark/web/bp.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ describe('bp', function() {
5757
674.64,701.78,668.33,662.15,663.34,677.32,664.25,1233.00,1100.80,716.15,681.52,671.23,702.70,686.89,939.39,830.28,695.46,695.66,675.15,667.48], 750.38)).toBe(158.57877026559186);
5858
});
5959
});
60+
61+
62+
describe('.calculateCoefficientOfVariation()', function() {
63+
expect(bp.Statistics.calculateCoefficientOfVariation(0.5, 5)).toBe(0.1);
64+
});
6065
});
6166

6267

benchmark/web/tree.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
<br>
7373
deviation: <%= timesStandardDeviation %>
7474
<br>
75+
coefficient of variation: <%= Math.round(coefficientOfVariation * 100) %>%
76+
<br>
7577
gc:<%= avg.gcTime %>ms
7678
<br>
7779
combined: <%= avg.combinedTime %>ms

0 commit comments

Comments
 (0)