[Haskell] Haskell fast (?) arrays

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue May 1 11:00:24 EDT 2007

>    Of course I know that the list version is very unfair, but I
>    wanted to see what was the trade off between elegance and
>    speed.
>    Regarding whether low level programming makes sense or not,
>    I was just curious to see what are the limits of Haskell.
>    Moreover there is not much literature on high performance
>    Haskell programming (tricks like unsafeWrite), at least
>    organized in a systematic and concise way.
>    My original problem was writing a  fast library for simple
>    matrix computations (i.e. multiplication and inversion for
>    small dense matrices).  I have not been able to make
>    GSLHaskell work with Lapack so far. :(
>    Anyway here are the new versions and timings, I increased
>    the number of times the vector is reversed, I also compiled
>    everything with -O2.

Probably a good idea to use techniques from Data.ByteString (ie. use
strict Ptr loops, and Foreign arrays), or techniques from the shootout,
if you're chasing C speed. Good examples are:

    (mutable bit arrays)

    (mutable byte (foreign) arrays)

    (more mutable arrays)

When I really really care about speed, I use 


and apply ! patterns liberally, checking the Core output for inner
loops. -O2 -optc-O2 -optc-march=pentium4 often helps.

1-4x C is around what you can best hope for. 10x says "still room for
improvement" in my experience.

-- Don

More information about the Haskell mailing list