readArray is faster than unsafeRead

Scott Dillard sedillard at ucdavis.edu
Tue May 29 17:42:22 EDT 2007


You're right. I broke them when experimenting to see where the cycles
were going. I've fixed them, but the other pair of functions, named
gaussElim2, were correct and the issue remains that unsafeRead appears
slower than readArray.

I've included your implementation for comparison, as well as a simple
pure matrix multiplication function, but I'm having trouble tracking
them down in the profiling. I think all of their cycles are being
counted under main, but I'm not sure how to stop this. They certainly
"feel" faster when I sit there and watch the program run, which is
great.

Why would lists-of-lists be faster than unboxed arrays? No indexing
arithmetic? Deforestation? I'm very curious. The first advice I got
from #haskell when trying to speed up my original code was "get rid of
all those lists."

Scott

On 5/29/07, Mirko Rahn <rahn at ira.uka.de> wrote:
>
> > instead of (!) (or readArray in stateful code) helped a lot. So then I
> > went to optimize my gaussian elimination function and found just the
> > opposite. unsafeRead is slower than readArray. This struck me as very
>
> The functions gaussElimSafe and gaussElimUnsafe are different in their
> outputs (*). I guess you made a mistake during conversion from one
> version to the other.
>
> BTW, the attached file contains an outline of a pure functional and
> indexless implementation. It calculates the inverse of a quadratic
> matrix in time O(n^3), so maybe you can get rid of all this exclamation
> marks and IO stuff...
>
> BR,
>
> (*) Try:
>
> newStdGen >>= \ g -> flip mapM_ [gaussElimSafe,gaussElimUnsafe] $ \ f ->
> makeMatrix g >>= \ m -> printMatrix m >> f m >> printMatrix m
>
> --
> -- Mirko Rahn -- Tel +49-721 608 7504 --
> --- http://liinwww.ira.uka.de/~rahn/ ---
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Test.hs
Type: text/x-haskell
Size: 12147 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20070529/d56a3229/Test-0001.bin


More information about the Glasgow-haskell-users mailing list