From e27eb8abaf99d0016aaa6badffb6568888483c6d Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 17 Nov 2009 02:04:38 +0100 Subject: [PATCH] Specialize the math functions The statistics functions are currently defined as polymorphic with a Floating constraint. Changing this to monomorphic on Double type makes them stricter and much more performant (~70% speedup). This is a cheap way to recoup some of the loses incurred by the recent proliferation of metrics. --- Ganeti/HTools/Utils.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Ganeti/HTools/Utils.hs b/Ganeti/HTools/Utils.hs index 9c1dff5bd..66722806f 100644 --- a/Ganeti/HTools/Utils.hs +++ b/Ganeti/HTools/Utils.hs @@ -81,11 +81,11 @@ fst3 (a, _, _) = a -- Simple and slow statistical functions, please replace with better versions -- | Mean value of a list. -meanValue :: Floating a => [a] -> a +meanValue :: [Double] -> Double meanValue lst = sum lst / fromIntegral (length lst) -- | Standard deviation. -stdDev :: Floating a => [a] -> a +stdDev :: [Double] -> Double stdDev lst = let mv = meanValue lst av = foldl' (\accu em -> let d = em - mv in accu + d * d) 0.0 lst @@ -93,7 +93,7 @@ stdDev lst = in bv -- | Coefficient of variation. -varianceCoeff :: Floating a => [a] -> a +varianceCoeff :: [Double] -> Double varianceCoeff lst = stdDev lst / fromIntegral (length lst) -- * JSON-related functions -- GitLab