import System.Environment import Text.Printf main = do [d] <- map read `fmap` getArgs printf "%f\n" (mean [1..d]) mean :: [Double] -> Double mean xs = sum xs / fromIntegral (length xs) {- Collect time statistics time Mean 2e7 -- Use GHC runtime system to collect statistics about heap usage and GC -- ... +RTS args -RTS passes args to the RTS Mean 2e7 +RTS -sstderr --Individual cost centers may be installed e.g. by mean xs = {-# SCC "mean" #-} sum xs / fromIntegral (length xs) -- Automatically generate cost centers ghc --make Mean.hs -prof -auto-all -caf-all -fforce-recomp -- RTS -p option generates .prof file -- RTS -K100M increases the stacK size to 100M (needed for profiling overhead) time Mean 1e6 +RTS -p -K100M time Mean 2e6 +RTS -p -K100M cat Mean.prof -- Heap profiling -hc sampling every -i sec time Mean 2e6 +RTS -hc -i0.03 -p -K100M hp2ps -c Mean.hp gv Mean.ps -- Allocation split by type -hy time Mean 2e6 +RTS -hy -i0.03 -p -K100M -- Allocation split by data constructor -hd time Mean 2e6 +RTS -hd -i0.03 -p -K100M -- Problem: mean traverses list twice! -}