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

Commit

Permalink
feat(benchmark): calculate coefficient of variation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffbcross committed Jun 18, 2014
1 parent c21ac7e commit fc09af2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion benchmark/web/bp.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ bp.Statistics.calculateConfidenceInterval = function(standardDeviation, sampleSi
return bp.Statistics.criticalValue * standardError;
};

bp.Statistics.calculateRelativeMarginOfError = function (marginOfError, mean) {
bp.Statistics.calculateRelativeMarginOfError = function(marginOfError, mean) {
/*
* Converts absolute margin of error to a relative margin of error by
* converting it to a percentage of the mean.
*/
return (marginOfError / mean);
};

bp.Statistics.calculateCoefficientOfVariation = function(standardDeviation, mean) {
return standardDeviation / mean;
};

bp.Statistics.calculateStandardDeviation = function(sample, mean) {
var deviation = 0;
sample.forEach(function(x) {
Expand Down Expand Up @@ -256,6 +260,7 @@ bp.Report.calcStats = function() {
avg: avg,
times: tpa.fmtTimes,
timesStandardDeviation: timesStandardDeviation,
coefficientOfVariation: bp.Statistics.calculateCoefficientOfVariation(timesStandardDeviation, avg.time),
timesRelativeMarginOfError: bp.Statistics.calculateRelativeMarginOfError(timesConfidenceInterval, avg.time),
gcTimes: tpa.fmtGcTimes,
garbageTimes: tpa.fmtGarbageTimes,
Expand Down
5 changes: 5 additions & 0 deletions benchmark/web/bp.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ describe('bp', function() {
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);
});
});


describe('.calculateCoefficientOfVariation()', function() {
expect(bp.Statistics.calculateCoefficientOfVariation(0.5, 5)).toBe(0.1);
});
});


Expand Down
2 changes: 2 additions & 0 deletions benchmark/web/tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<br>
deviation: <%= timesStandardDeviation %>
<br>
coefficient of variation: <%= Math.round(coefficientOfVariation * 100) %>%
<br>
gc:<%= avg.gcTime %>ms
<br>
combined: <%= avg.combinedTime %>ms
Expand Down

0 comments on commit fc09af2

Please sign in to comment.