From c3147a6b56556af23e8d52931704a88496ed1eb3 Mon Sep 17 00:00:00 2001 From: Nicolas Bacquey Date: Wed, 9 Jan 2019 17:24:17 +0100 Subject: [PATCH 1/2] Added linear regression to compute execution time Fixes #40, Added information to report display --- src/Hyperion/Analysis.hs | 12 +++++++++++- src/Hyperion/PrintReport.hs | 6 +++++- src/Hyperion/Report.hs | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Hyperion/Analysis.hs b/src/Hyperion/Analysis.hs index a38a61b..4777bfd 100644 --- a/src/Hyperion/Analysis.hs +++ b/src/Hyperion/Analysis.hs @@ -14,6 +14,7 @@ import Control.Lens , foldMapOf , folded , to + , toListOf ) import Control.Lens.Each @@ -23,6 +24,8 @@ import Hyperion.Benchmark import Hyperion.Internal import Hyperion.Measurement import Hyperion.Report +import Statistics.Regression +import qualified Data.Vector.Unboxed as UV identifiers :: Fold Benchmark BenchmarkId identifiers = go [] @@ -47,7 +50,10 @@ analyze ident samp = Report , _reportBenchParams = map (\(Parameter x) -> fromEnum x) $ benchmarkParameters ident , _reportTimeInNanos = - totalDuration / trueNumIterations + totalDuration / trueNumIterations + , _linearRegressionTime = slope + , _linearRegressionConstant = yIntercept + , _linearRegressionConfidence = determinationCoefficient , _reportCycles = Nothing , _reportAlloc = Nothing , _reportGarbageCollections = Nothing @@ -64,3 +70,7 @@ analyze ident samp = Report Sum (foldMapOf (measurements.each.batchSize.to realToFrac)) samp + ([slope,yIntercept],determinationCoefficient) = (\(v,r) -> (UV.toList v,r)) $ olsRegress [batchSizesVect] durationsVect + where + batchSizesVect = UV.fromList $ fromIntegral <$> toListOf (measurements.each.batchSize) samp + durationsVect = UV.fromList $ fromIntegral <$> toListOf (measurements.each.duration) samp diff --git a/src/Hyperion/PrintReport.hs b/src/Hyperion/PrintReport.hs index e9f8bc2..27e1da8 100644 --- a/src/Hyperion/PrintReport.hs +++ b/src/Hyperion/PrintReport.hs @@ -14,7 +14,11 @@ import Text.PrettyPrint.ANSI.Leijen formatReport :: Report -> Doc formatReport report = green (bold (text (unpack (view reportBenchName report)))) <> line - <> (indent 2 $ text ("Bench time: " ++ prettyNanos (view reportTimeInNanos report))) + <> (indent 2 $ text ("Bench time: " ++ prettyNanos (view reportTimeInNanos report))) <> line + <> (indent 2 $ text ("Computed with linear regression: ")) <> line + <> (indent 4 $ text ("Bench time: " ++ prettyNanos (view linearRegressionTime report))) <> line + <> (indent 4 $ text ("Constant factor: " ++ prettyNanos (view linearRegressionConstant report))) <> line + <> (indent 4 $ text ("Confidence: " ++ showFFloat (Just 4) (view linearRegressionConfidence report) "")) <> line where show2decs x= showFFloat (Just 2) x "" diff --git a/src/Hyperion/Report.hs b/src/Hyperion/Report.hs index f5de886..949aec1 100644 --- a/src/Hyperion/Report.hs +++ b/src/Hyperion/Report.hs @@ -25,6 +25,9 @@ data Report = Report { _reportBenchName :: !Text , _reportBenchParams :: [Int] , _reportTimeInNanos :: !Double + , _linearRegressionTime :: !Double + , _linearRegressionConstant :: !Double + , _linearRegressionConfidence :: !Double , _reportCycles :: !(Maybe Double) , _reportAlloc :: !(Maybe Int64) , _reportGarbageCollections :: !(Maybe Int64) From 1ca4c3bba006ca1afeb82c34eb132df9858040c3 Mon Sep 17 00:00:00 2001 From: Arnaud Spiwack Date: Wed, 9 Jan 2019 21:18:11 +0100 Subject: [PATCH 2/2] Update src/Hyperion/Analysis.hs Co-Authored-By: nbacquey <38809035+nbacquey@users.noreply.github.com> --- src/Hyperion/Analysis.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Hyperion/Analysis.hs b/src/Hyperion/Analysis.hs index 4777bfd..5c0c465 100644 --- a/src/Hyperion/Analysis.hs +++ b/src/Hyperion/Analysis.hs @@ -70,7 +70,7 @@ analyze ident samp = Report Sum (foldMapOf (measurements.each.batchSize.to realToFrac)) samp - ([slope,yIntercept],determinationCoefficient) = (\(v,r) -> (UV.toList v,r)) $ olsRegress [batchSizesVect] durationsVect + ([slope,yIntercept],determinationCoefficient) = over _1 UV.toList $ olsRegress [batchSizesVect] durationsVect where batchSizesVect = UV.fromList $ fromIntegral <$> toListOf (measurements.each.batchSize) samp durationsVect = UV.fromList $ fromIntegral <$> toListOf (measurements.each.duration) samp