On Fri, Feb 8, 2013 at 1:23 PM, Aleksey Khudyakov <alexey.skladnoy@gmail.com> wrote:
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.

Thanks for the suggestion, I will try that.

 
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?

Yes, a histogram. The binning code is really a little awkward. I haven't gotten used to thinking in terms of inmutable objects yet and this list appending is really a pretty bad hack to kind of allow me to increment the bin counts. How would one do this more haskellishish?

 


The Haskell script was compiled with "ghc --make printMatrixDecay.hs".

If you want performance you absolutely should use -O2.

I'll try that.

 

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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe