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.
Hi Aleksey,
could you show me how I would use ByteString? I can't get the script to compile. It's complaining that: No instance for (RegexContext Regex Data.ByteString.ByteString (AllTextSubmatches [] a0)) which is too cryptic for me. Is it not able to form a regular expression with a ByteString argument? From the documentation of Text.Regex.Posix it seems that it should be. Maybe it's because I am trying to "read (r!!1) :: Double" which I am having issues with also. Is (r!!1) a ByteString? And if so, how would I convert that to a Double? Thanks, nick
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<http://hackage.haskell.org/package/text> [2] http://hackage.haskell.org/**package/bytestring<http://hackage.haskell.org/package/bytestring>
______________________________**_________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/**mailman/listinfo/haskell-cafe<http://www.haskell.org/mailman/listinfo/haskell-cafe>