Optimize the Utils.stdDev function
authorIustin Pop <iustin@google.com>
Mon, 6 Jul 2009 22:20:41 +0000 (00:20 +0200)
committerIustin Pop <iustin@google.com>
Mon, 6 Jul 2009 22:22:54 +0000 (00:22 +0200)
commite6f4f05c9c4fb1ddbb3726445fad88f171dab985
tree27d9723c9a2cb963d31560e2299bf8669c9667c2
parentd71d0a1dca102d0ef8b035a061d51c4e69d8fd19
Optimize the Utils.stdDev function

This patch optimizes the stdDev function in two respects:
  - first, we don't do sum . map which builds an intermediate list, but
instead use a fold over the list to build incrementally the sum;
this should reduce both the time and space characteristics, as we
have fewer objects created
  - second, we move from “a ^ 2” to “a * a” as the latter has a much
simpler implementation and thus a higher performance

Since the ‘square’ function is obsoleted by the above the patch also
removes it.
Ganeti/HTools/Utils.hs