diff --git a/src/Hyperion/Analysis.hs b/src/Hyperion/Analysis.hs index a38a61b..5c0c465 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) = 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 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)