[Haskell-cafe] Re: How to optimize the performance of a code in
Haskell?
Kalman Noel
noel.kalman at googlemail.com
Wed Nov 4 11:53:49 EST 2009
(I take it you accidently wrote to fa.haskell, which is just a mirror of -cafe
and -beginners, so I'm cc-ing the Café with a full quote.)
Masayuki Takagi:
> I'm writing fluid simulation programs with SPH(Smoothed particle
> hydrodynamics) in Haskell and C++. (The purpose that I write in two
> languages is to make a workflow that first i write in Haskell for
> rapid prototyping and accuracy then rewrite in C++ for performance.)
>
> I've compared them in performance. Then, although I have already done
> optimization with profiler, the Haskell code is 20 times slower than
> the C++ code.
>
> I think the performance of the Haskell code is so slow that there can
> be room for optimization. I'm happy if the Haskell code work 3 times
> slower than the C++ code at worst.
>
> How can I make the Haskell code faster?
> What information should I refer?
>
> The codes are here:
> http://kamonama.sakura.ne.jp/sph/20091101/sph.hs.zip
> http://kamonama.sakura.ne.jp/sph/20091101/sph.cpp
>
> To run the code in Haskell:
> $ ghc --make -O sph.hs
> $ ./sph 300
> (300 is the time step to be conputed)
>
> To run the code in C++:
> $ g++ -O2 -o sph sph.cpp
> $ ./sph 300
> (300 is the time step to be conputed)
>
> thanks
>
I've not looked at the code, but you'll want ghc to do better optimizations
than -O. -O2 is what you should use in general. Also, number-crunching often
profits from -fexcess-precision.
More information about the Haskell-Cafe
mailing list