[Haskell-cafe] Are there performant mutable Arrays in Haskell?

Bulat Ziganshin bulat.ziganshin at gmail.com
Thu Mar 19 07:54:04 EDT 2009


Hello Matthias,

Thursday, March 19, 2009, 2:16:30 PM, you wrote:

1. use ghc -O2
2. use unsafeRead/WriteArrray
3. check that all calculations (step*, li/ri) are strict

> Hey There, 

> I am trying to write a hash-algorithm that in fact is working, but
> as you might have guessed the problem is the performance :) At the
> moment I am 40 times worse than the same implementation in C. 

> My problem is, I need mutable arrays which are the heart of that hash.
> The algorithm is round-based and within each round I need the value
> of certain positions in that array. 

> At the moment I work with an unboxed ST-Array at the crucial part 

> --- snip ---
> test list = runSTUArray $ do
>     a_arr <- newListArray (0, 1752) list

>     let round i = do
>             ain <- readArray a_arr (i-n)
>             at0 <- readArray a_arr (i-t0)
>             at1 <- readArray a_arr (i-t1)
>             at2 <- readArray a_arr (i-t2)
>             at3 <- readArray a_arr (i-t3)
>             at4 <- readArray a_arr (i-t4)
>             let li     = ls $ (i - n) mod 16
>                 ri     = rs $ (i - n) mod 16

>             writeArray a_arr i $ (step4 li) 
>                                . (step3 ri) 
>                                . (step2 at1 at2 at3 at4)
>                                $ (step1 ain at0 i)
>     mapM_ round [n..(n+t-1)]

>     return a_arr
> --- snap ---

> I also played around with peekElemOff and pokeElemOff, but this isn't much faster.
> It took ~30sec with my Haskell-Code while the C-implementation need only ~1sec.

> Is there someone who may have some hints for me, what I can do better, or just
> lead me in the right direction? :) 

> Thanks a lot in advance 

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



-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list