[Haskell-beginners] Speed performance problem on Windows?

Daniel Fischer daniel.is.fischer at web.de
Fri Mar 5 19:36:16 EST 2010

Am Samstag 06 März 2010 00:20:52 schrieb Travis Erdman:
> 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:
> 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 ...

Not the best combination of options, for me at least. On my box, that is 
approximately 35% slower than -O2 with the native code generator.

> On the final test of 10^9, Don reports that it took 1.76 secs on his
> machine.

Well, Don has a super fast 64-bit thingy, on normal machines, all code runs 
much slower than on Don's :)

> In contrast, just 10^8 takes 12.63 secs on my machine

But not that much slower, ouch.

On my machine, 10^8 takes
~3.8s compiled with -O2 -fvia-C -optc-O2 [or -optc-O3, doesn't make a 
~2.8s compiled with -O2 [with and without -fexcess-precision]
~1.18s compiled with -O2 -fexcess-precision -fvia-C -optc-O3

Floating point arithmetic compiled via C profits greatly from -fexcess-
precision (well, at least on my system, YMMV).

Alas, equivalent gcc-compiled C code takes only 0.35s for 10^8 (0.36 with 

Multiply all timings by 10 for 10^9.

> (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.

I also have 3.06GHz P4 (2 cores, 1 GB RAM), running openSuSE 11.1 and 
ghc-6.12.1, ghc-6.10.3 (no difference between 6.10 and 6.12 for this loop).
The P4 isn't particularly fast, unfortunately.

> Primary question:  What gives here?

GCC on XP sucks. Big time, AFAIK. Compile your stuff once via C and once 
with the native code generator and compare. I think you'll almost always 
find the NCG faster, sometimes very much.

> Incidental questions:  Is there a nice way to time executed code in
> Windows ala the "time" command Don shows under Linux?

There's timeit.exe, as linked to in 

> Also, does the
> ordering of the compiler flags have any impact (I hope not, but I don't
> want to be surprised ...)

Depends. If you give conflicting options, the last takes precedence (unless 
some combination gives an error, don't know if that happens). If the 
options aren't conflicting, the order doesn't matter.

> Thanks,
> Travis Erdman

More information about the Beginners mailing list