Faster, GHC, and floating point.

JP Bernardy jyp_7 at
Thu Oct 16 04:56:06 EDT 2003

Hi all,

> Generally, did you look at

I have to say that one advice is not perfect...

"Don't use Floats:
"...There's rarely a speed disadvantage --
"modern machines will use the same floating-point
"unit for both. ...

Assuming an i386 architecture, the way to get really
faster code is

1. Use -fexcess-precision, unless you really need the
exact (lesser) precision. Otherwise each intermediate
result is spilled in memory. This hurts!

2. Use floats rather than doubles. You won't lose so
much precision because all intermediate computations
will use 80-bit precision. This saves some memory.
Plus, GHC doesn't align on 64 bits, which slows down
access to doubles.

I've made up a simple benchmark with Andreas' code,
using the pure haskell "aibd", with main:

tt z = print $ sum $ map (\x -> rechneZins x 0.01 z) $

main = 
    do tt 20
       tt 21
       tt 30

ghc -O2 -fglasgow-exts --make Main.hs, a.out runs in
7.82 secs.
with -fexcess-precision, runs in 2.97secs;
with Float instead of Double, runs in 2.72secs.

This is with gcc 3.3.2, ghc 6.0.1, linux and a
pentium4 arch.

Just my 2 cents,


Do you Yahoo!?
The New Yahoo! Shopping - with improved product search

More information about the Glasgow-haskell-users mailing list