[Haskell-cafe] performance question

Aleksey Khudyakov alexey.skladnoy at gmail.com
Fri Feb 8 21:23:58 CET 2013


On 08.02.2013 23:26, Nicolas Bock wrote:
> Hi list,
>
> I wrote a script that reads matrix elements from standard input, parses
> the input using a regular expression, and then bins the matrix elements
> by magnitude. I wrote the same script in python (just to be sure :) )
> and find that the python version vastly outperforms the Haskell script.
>
General performance hints

1) Strings are slow. Fast alternatives are text[1] for textual data and 
bytestrings[2] for binary data. I can't say anything about performance 
of Text.Regex.Posix.

2) Appending list wrong operation to do in performance sensitive code.
(++) traverses its first argument so it's O(n) in its length.


What exactly are you tryeing to do? Create a histogram?


> The Haskell script was compiled with "ghc --make printMatrixDecay.hs".
>
If you want performance you absolutely should use -O2.


[1] http://hackage.haskell.org/package/text
[2] http://hackage.haskell.org/package/bytestring



More information about the Haskell-Cafe mailing list