From fc09af2c880bf741abe8c9284805a92bd63f8742 Mon Sep 17 00:00:00 2001 From: Jeff Cross Date: Wed, 18 Jun 2014 09:46:16 -0700 Subject: [PATCH] feat(benchmark): calculate coefficient of variation --- benchmark/web/bp.js | 7 ++++++- benchmark/web/bp.spec.js | 5 +++++ benchmark/web/tree.html | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/benchmark/web/bp.js b/benchmark/web/bp.js index e0fe43cf6..68130c4da 100644 --- a/benchmark/web/bp.js +++ b/benchmark/web/bp.js @@ -43,7 +43,7 @@ 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. @@ -51,6 +51,10 @@ bp.Statistics.calculateRelativeMarginOfError = function (marginOfError, 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) { @@ -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, diff --git a/benchmark/web/bp.spec.js b/benchmark/web/bp.spec.js index 92832f9eb..455c820fa 100644 --- a/benchmark/web/bp.spec.js +++ b/benchmark/web/bp.spec.js @@ -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); + }); }); diff --git a/benchmark/web/tree.html b/benchmark/web/tree.html index d07f4c7ef..cb8d6bcb7 100644 --- a/benchmark/web/tree.html +++ b/benchmark/web/tree.html @@ -72,6 +72,8 @@
deviation: <%= timesStandardDeviation %>
+ coefficient of variation: <%= Math.round(coefficientOfVariation * 100) %>% +
gc:<%= avg.gcTime %>ms
combined: <%= avg.combinedTime %>ms