[Haskell-cafe] Performance: MD5

Andrew Coppin andrewcoppin at btinternet.com
Sat May 17 10:51:27 EDT 2008

Hi folks.

OK, try this:

  darcs get http://darcs.orphi.me.uk/MyMD5
  cd MyMD5
  ghc -O2 --make md5sum
  md5sum <some large filename>

On my PC, it takes 3.5 seconds to compute the MD5 hash of a 10 MB file. 
For comparison, the md5.exe I downloaded from the Internet does it 
instantaneously. It's literally so fast I can't even time it. As far as 
I know, my program always produces the *correct* answer, it just takes 
far too long to do it.

If anybody has any interesting insights as to why my version is so 
damned slow, I'd like to hear them. (Indeed, a description of the 
process for tracking the problem down would also be useful!)

[Much to my bemusement, when I had a look at the code, I discovered that 
tucked away in a corner somewhere, it reads a ByteString from disk and 
instantly converts it to [Word8]. Uh... oops? Anyway, eliminating this 
changed the numbers I get from the profiler, but it's still far too slow.]

More information about the Haskell-Cafe mailing list