[Haskell-cafe] sha1 implementation thats "only" 12 times slower then C

Bulat Ziganshin bulat.ziganshin at gmail.com
Sun Jul 1 10:04:56 EDT 2007


Hello Anatoly,

Sunday, July 1, 2007, 3:58:24 AM, you wrote:

> Anyone have any pointers on how to get hashElem and updateElem to run
> faster, or any insight on what exactly they are allocating.  To me it
> seems that those functions should be able to do everything they need
> to without a malloc.

haskell allocations isn't a malloc, it's just a pointer increment, so
it's very fast. any temporary data created in haskell code need to be
allocated so the only case when you don't have allocations is cycle on
unboxed values

in your particular case you should try the following trick:

   aa <- unsafeRead a5 0
   return $! aa
   bb <- unsafeRead a5 1
   return $! bb

currently, your code implies that unsafeRead may return boxed value.
'let' by itself doesn't enforce unboxing, the compiler implies that
value assigned in 'let' may be actually not used. you can use either
'case' or above-mentioned trick with '$!' (or seq) to avoid boxing

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



More information about the Haskell-Cafe mailing list