[Haskell-cafe] haskell crypto is reaaaaaaaaaally slow

Donald Bruce Stewart dons at cse.unsw.edu.au
Wed Jun 20 00:56:08 EDT 2007


stefanor:
> On Wed, Jun 20, 2007 at 01:24:00PM +1000, Donald Bruce Stewart wrote:
> > aeyakovenko:
> > > $ time ./md5sum ./md5sum
> > > [105,252,52,138,187,192,216,17,225,123,185,3,124,101,86,132]
> > > 
> > > real    0m4.790s
> > > user    0m3.688s
> > > sys     0m0.492s
> > > 
> > > $ time md5sum ./md5sum
> > > 69fc348abbc0d811e17bb9037c655684  ./md5sum
> > > 
> > > real    0m0.023s
> > > user    0m0.000s
> > > sys     0m0.008s
> > > 
> > > this is my implementation using crypto
> > > (http://www.haskell.org/crypto/).  Am I doing something wrong?
> > > 
> > > module Main where
> > > 
> > > import System
> > > import qualified Data.Digest.MD5 as MD5
> > > import qualified Data.ByteString as BS
> > > 
> > > main = do
> > >   args <- getArgs
> > >   dt <- BS.readFile $ head args
> > >   putStrLn $ show $ MD5.hash . BS.unpack $ dt
> >                ^^^^              ^^^^^^^^^
> > 
> >                                  not a good idea.
> > 
> > You need an MD5 over bytestrings, not [Word8].
> 
> Wouldn't deforestation have produced something within a factor of 4-ish
> of optimal?

There's no deforestation between ByteString.unpack and MD5.hash.

So all the time here is spent taking some big bytestring, and unpacking
it into n list cons cells. md5ing the bytestring directly should knock
95% off that.

-- Don


More information about the Haskell-Cafe mailing list