Faster, GHC, and floating point.

Andreas.Schroeder at gillardon.de Andreas.Schroeder at gillardon.de
Fri Oct 17 11:57:55 EDT 2003


Hi all,

using -fexcess-precision improves the runtime from about 180259 ns to
140201 ns on my environment (Intel P3, 700Mhz, 384 MB Ram, Win2k).
That makes for me a speedup of 1.29. I tested the other flags,
-funbox-strict-fields -fliberate-case-threshold100 but did not see an
improvement.
Well, pure Haskell has a runtime of

140201 ns

as stated above for a test of 9000 calls (thanks to the "sum $ map f
[inputlist]" pattern!). If i use the C aibd as foreign call, i get a
runtime of

80115 ns

That's pretty good (both ghc6.0.1 on MinGW windows env). But if i look at
my Java or C++ solution, then  Java takes for the same task (JVM 1.4.2_01
client vm)

30000 ns.

The resolution of the currenttimemillis is pretty poor in Java. It's
neither better in C++, but i guess that's because of my Arch. At home, i
got a better timer resolution than that.
(wich i was able to lookup  through Haskell). The C++ version lies
somewhere between

20000 ns and 10000 ns, close to 20000 ns. I guess it's 18000 ns.

That's still the difference of 4 to 6 between C++ and Haskell. I will look
at the "core source" generated by GHC to look if it is good enough.

For interested souls, i will put the C++ code as well as the haskell code
on an FTP server. FTP access details will come soon.

Currently, i am setting up a second test. While this first study
concentrates on "numbers", and does not provide much data structures, the
second study i will do concentrates on complex data structures
(yup, i will have a GREAT time with C++, since i "only" learned Java,
Haskell, SML, MIPS assembler, ProLog, ... at the University)

Thanks to all for your great help so far,
Andreas Schroeder



|---------+----------------------------------------->
|         |           JP Bernardy <jyp_7 at yahoo.com> |
|         |           Gesendet von:                 |
|         |           glasgow-haskell-users-bounces@|
|         |           haskell.org                   |
|         |                                         |
|         |                                         |
|         |           16.10.2003 12:56              |
|         |                                         |
|---------+----------------------------------------->
  >-------------------------------------------------------------------------------------------------------------------|
  |                                                                                                                   |
  |        An:      glasgow-haskell-users at haskell.org                                                                 |
  |        Kopie:                                                                                                     |
  |        Thema:   Faster, GHC, and floating point.                                                                  |
  >-------------------------------------------------------------------------------------------------------------------|



Hi all,

> Generally, did you look at
http://haskell.org/ghc/docs/latest/html/users_guide/faster.html

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) $
[1..10000]

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,
JP.














__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users at haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users







More information about the Glasgow-haskell-users mailing list