Skip to content

Commit

Permalink
Added more summary functions to analysis and output
Browse files Browse the repository at this point in the history
  • Loading branch information
dmpots committed Sep 30, 2010
1 parent 1946703 commit 5ef5767
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 53 deletions.
77 changes: 48 additions & 29 deletions tools/fibon-analyse/Fibon/Analyse/Analysis.hs
Expand Up @@ -87,8 +87,18 @@ computeRows :: [(Normalize a, ResultColumn a)]
computeRows resultColumns benchs colSpecs = do
rows <- mapM (computeOneRow resultColumns colSpecs) benchs
let colData = transpose $ map snd rows
meanRow <- mapM summarize colData
return (rows, [("mean", meanRow)])
doSumm how = mapM (summarize how) colData
minRow <- doSumm Min
meanRow <- doSumm GeoMean
arithRow <- doSumm ArithMean
maxRow <- doSumm Max
let sumRows = [
("min", minRow)
, ("geomean", meanRow)
, ("arithmean", arithRow)
, ("max", maxRow)
]
return (rows, sumRows)

computeOneRow :: [(Normalize a, ResultColumn a)]
-> [ColSpec a]
Expand All @@ -111,10 +121,12 @@ computeOneColumn bench (ColSpec _ metric) (normType, resultColumn) =
case normType of
NormPercent base -> normToBase base normalizePercent
NormRatio base -> normToBase base normalizeRatio
NormNone _ -> return (Raw peak)
NormNone _ -> return (mkRaw peak)
where
mkRaw = Basic . Raw
mkNorm = Basic . Norm
normToBase base normFun = maybe (return NoResult)
(\b -> Norm `liftM` normFun b peak)
(\b -> mkNorm `liftM` normFun b peak)
(getRawPerf base)
getRawPerf rc = perf $ fmap metric ((M.lookup bench . results) rc)

Expand Down Expand Up @@ -151,61 +163,68 @@ norm c f toDouble base peak =
c (mkPointEstimate mkStddev (f (toDouble base) (toDouble peak)))
where mkStddev = fromIntegral :: Int -> Double

summarize :: [PerfData] -> PerfMonad PerfData
summarize perfData =
summarize :: Summary -> [PerfData] -> PerfMonad PerfData
summarize how perfData =
case (normData, rawData) of
([], []) -> return NoResult
(nd, []) -> (summarizeNorm nd) >>= return . Summary
([], rd) -> (summarizeRaw rd) >>= return . Summary
(nd, []) -> summarizeNorm how nd
([], rd) -> summarizeRaw how rd
_ -> throwError "Mixed raw and norm results in column"
where
normData = getData (\p -> case p of Norm n -> Just n ; _ -> Nothing)
rawData = getData (\p -> case p of Raw r -> Just r ; _ -> Nothing)
normData = getData (\p -> case p of Basic (Norm n) -> Just n ; _ -> Nothing)
rawData = getData (\p -> case p of Basic (Raw r) -> Just r ; _ -> Nothing)
getData f = (catMaybes . map f) perfData

summarizeRaw :: [RawPerf] -> PerfMonad SummaryPerf
summarizeRaw rawPerfs =
summarizeRaw :: Summary -> [RawPerf] -> PerfMonad PerfData
summarizeRaw how rawPerfs =
case (isTime rawPerfs, isSize rawPerfs) of
(True, _) -> summarizeRaw' ExecTime RawTime rawPerfs
(_, True) -> summarizeRaw' (MemSize . round) RawSize rawPerfs
(True, _) -> summarizeRaw' how ExecTime RawTime rawPerfs
(_, True) -> summarizeRaw' how (MemSize . round) RawSize rawPerfs
_ -> throwError "Can only summarize column with time or size"
where
isTime = all (\r -> case r of RawTime _ -> True; RawSize _ -> False)
isSize = all (\r -> case r of RawSize _ -> True; RawTime _ -> False)

summarizeRaw' :: (Double -> a) -- ^ rounding function
summarizeRaw' :: Summary -- ^ what kind of summary
-> (Double -> a) -- ^ rounding function
-> (Estimate a -> RawPerf) -- ^ RawPerf constructor
-> [RawPerf] -- ^ Performance numbers to summary
-> PerfMonad SummaryPerf
summarizeRaw' roundFun makeRaw rawPerfs =
return $ ArithMean (makeRaw (fmap roundFun (computeSummary mean vec)))
-> PerfMonad PerfData
summarizeRaw' how roundFun makeRaw rawPerfs =
return $ Summary how (Raw (makeRaw (fmap roundFun (computeSummary how vec))))
where
vec = V.fromList (map rawPerfToDouble rawPerfs)

summarizeNorm :: [NormPerf] -> PerfMonad SummaryPerf
summarizeNorm normPerfs =
summarizeNorm :: Summary -> [NormPerf] -> PerfMonad PerfData
summarizeNorm how normPerfs =
case (isPercent normPerfs, isRatio normPerfs) of
(True, _) -> summarizeNorm' Percent normPerfs
(_, True) -> summarizeNorm' Ratio normPerfs
(True, _) -> summarizeNorm' how Percent normPerfs
(_, True) -> summarizeNorm' how Ratio normPerfs
_ -> throwError "Can only summarize column with percent or ratio"
where
isPercent = all (\r -> case r of Percent _ -> True; Ratio _ -> False)
isRatio = all (\r -> case r of Percent _ -> False; Ratio _ -> True)

summarizeNorm' :: (Estimate Double -> NormPerf)
summarizeNorm' :: Summary
-> (Estimate Double -> NormPerf)
-> [NormPerf]
-> PerfMonad SummaryPerf
summarizeNorm' makeNorm normPerfs =
return $ GeoMean (makeNorm (computeSummary geometricMean vec))
-> PerfMonad PerfData
summarizeNorm' how makeNorm normPerfs =
return $ Summary how (Norm (makeNorm (computeSummary how vec)))
where
vec = V.fromList (map normPerfToDouble normPerfs)

computeSummary :: (Sample -> Double) -> Sample -> Estimate Double
computeSummary sumF vec =
computeSummary :: Summary -> Sample -> Estimate Double
computeSummary summaryType vec =
Estimate {
ePoint = sumF vec
ePoint = sumF summaryType vec
, eStddev = stdDev vec -- TODO: this is wrong stddev for geoMean
, eSize = V.length vec
, eCI = Nothing
}
where
sumF ArithMean = mean
sumF GeoMean = geometricMean
sumF Max = V.maximum
sumF Min = V.minimum

12 changes: 0 additions & 12 deletions tools/fibon-analyse/Fibon/Analyse/Main.hs
Expand Up @@ -33,15 +33,3 @@ simpleAnalysis = Analysis {

}


--t1 = basicTable
--
--t3 = [ColumnSpec "time" (Just . compileTime),
-- ColumnSpec "gc" (fmap d . extraStats)
-- ]

-- foo :: [MetricFormat]
-- foo =
-- map (\(Column _ f, r) -> toFormat $ fromJust (f r)) (zip t1 results)
-- where results = concat $ map M.elems $ parseResults (const Nothing) (B.empty)
--
34 changes: 22 additions & 12 deletions tools/fibon-analyse/Fibon/Analyse/Metrics.hs
Expand Up @@ -10,7 +10,8 @@ module Fibon.Analyse.Metrics (
, pprPerfData
, RawPerf(..)
, NormPerf(..)
, SummaryPerf(..)
, BasicPerf(..)
, Summary(..)
, mkPointEstimate
, rawPerfToDouble
, normPerfToDouble
Expand Down Expand Up @@ -84,9 +85,13 @@ instance Metric a => Metric (Maybe a) where

data PerfData =
NoResult
| Raw RawPerf
| Basic BasicPerf
| Summary Summary BasicPerf
deriving(Read, Show)

data BasicPerf =
Raw RawPerf
| Norm NormPerf
| Summary SummaryPerf
deriving(Read, Show)

data RawPerf =
Expand All @@ -99,16 +104,21 @@ data NormPerf =
| Ratio (Estimate Double) -- ^ (base / ref)
deriving(Read, Show)

data SummaryPerf =
GeoMean NormPerf
| ArithMean RawPerf
data Summary =
Min
| GeoMean
| ArithMean
| Max
deriving(Read, Show)

pprPerfData :: Bool -> PerfData -> String
pprPerfData _ NoResult = "--"
pprPerfData u (Raw r) = pprRawPerf u r
pprPerfData u (Norm n) = pprNormPerf u n
pprPerfData u (Summary s) = pprSummaryPerf u s
pprPerfData u (Basic b) = pprBasicPerf u b
pprPerfData u (Summary _ s) = pprBasicPerf u s

pprBasicPerf :: Bool -> BasicPerf -> String
pprBasicPerf u (Raw r) = pprRawPerf u r
pprBasicPerf u (Norm n) = pprNormPerf u n

pprNormPerf :: Bool -> NormPerf -> String
pprNormPerf u (Percent d) =
Expand Down Expand Up @@ -136,10 +146,10 @@ pprRawPerf u (RawSizeInterval e) = printf "%d%s%s"
pprPlusMinus :: Real b => Estimate a -> (a -> b) -> String
pprPlusMinus e f = printf "%c%0.2d" (chr 0xB1) ((realToFrac spread)::Double)
where spread = abs ((f . ePoint) e) - ((f . eLowerBound) e)
-}
pprSummaryPerf :: Bool -> SummaryPerf -> String
pprSummaryPerf u (GeoMean n) = pprNormPerf u n
pprSummaryPerf u (ArithMean r) = pprRawPerf u r
pprSummaryPerf u (GeoMean n) = pprBasicPerf u n
pprSummaryPerf u (ArithMean r) = pprBasicPerf u r
-}

pprUnit :: Bool -> String -> String
pprUnit True s = s
Expand Down

0 comments on commit 5ef5767

Please sign in to comment.