[Haskell-beginners] Speed performance problem on Windows?
Travis Erdman
traviserdman at yahoo.com
Fri Mar 5 18:20:52 EST 2010
I'm working through one of Don Stewart's many excellent articles ...
http://cgi.cse.unsw.edu.au/~dons/blog/2008/06/04#fast-fusion
I faithfully re-created the source of his initial GHC reference implementation as:
import System.Environment
import Text.Printf
mean :: Double -> Double -> Double
mean n m = go 0 0 n
where
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
500000.5
C:\Documents and Settings\Travis\My Documents\Haskell Code>biglistmean 10000000
5000000.5
C:\Documents and Settings\Travis\My Documents\Haskell Code>biglistmean 100000000
50000000.5
C:\Documents and Settings\Travis\My Documents\Haskell
Code>biglistmean 1000000000
500000000.067109
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 ...)
Thanks,
Travis Erdman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100305/41b01920/attachment.html
More information about the Beginners
mailing list