...by doing balanced summing, including computing the delta in the update first, and improving memory footprint by strictness.
Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/Utils/Statistics.hs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Ganeti/Utils/Statistics.hs b/src/Ganeti/Utils/Statistics.hs index 6277c5d..cd830fb 100644 --- a/src/Ganeti/Utils/Statistics.hs +++ b/src/Ganeti/Utils/Statistics.hs @@ -79,18 +79,16 @@ data MapStat = MapStat TagTagMap deriving Show instance Stat Double SumStat where calculate xs = - let addComponent s x = - let !s' = s + x - in s' - st = foldl' addComponent 0 xs - in SumStat st + let !sx = balancedSum xs + in SumStat sx update (SumStat s) x x' = - SumStat $ s + x' - x + let !sx' = s + (x' -x) + in SumStat sx' getValue (SumStat s) = s instance Stat Double StdDevStat where calculate xs = - let !n = fromIntegral $ lenth xs + let !n = fromIntegral $ length xs !sx = balancedSum xs !mean = sx / n sqDist x = let d = x - mean in d * d -- 2.6.0.rc2.230.g3dd15c0
