[Haskell-beginners] Speed performance problem on Windows?
traviserdman at yahoo.com
Fri Mar 5 18:20:52 EST 2010
I'm working through one of Don Stewart's many excellent articles ...
I faithfully re-created the source of his initial GHC reference implementation as:
mean :: Double -> Double -> Double
mean n m = go 0 0 n
go :: Double -> Int -> Double -> Double
go s l x | x>m = s / fromIntegral l
| otherwise = go (s+x) (l+1) (x+1)
main = do
[d] <- map read `fmap` getArgs
printf "%f\n" (mean 1 d)
Then, compiled and executed like this:
C:\Documents and Settings\Travis\My Documents\Haskell Code>ghc -O2 biglistmean.hs -optc-O2 -fvia-C --make -fforce-recomp
[1 of 1] Compiling Main ( biglistmean.hs, biglistmean.o )
Linking biglistmean.exe ...
C:\Documents and Settings\Travis\My Documents\Haskell Code>biglistmean 1000000
C:\Documents and Settings\Travis\My Documents\Haskell Code>biglistmean 10000000
C:\Documents and Settings\Travis\My Documents\Haskell Code>biglistmean 100000000
C:\Documents and Settings\Travis\My Documents\Haskell
On the final test of 10^9, Don reports that it took 1.76 secs on his machine. In contrast, just 10^8 takes 12.63 secs on my machine (sophisticatedly timed with handheld stopwatch) and on the coup de grace 10^9 test, it takes 2min:04secs. Yikes! My hardware is a little old (Win XP on Pentium 4 3.06GHz w 2 GB RAM) but not THAT old. I'm using the latest Haskell Platform which includes ghc v 6.10.4.
Primary question: What gives here?
Incidental questions: Is there a nice way to time executed code in Windows ala the "time" command Don shows under Linux? Also, does the ordering of the compiler flags have any impact (I hope not, but I don't want to be surprised ...)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners