[Haskell-cafe] estimating the speed of operation

Belka lambda-belka at yandex.ru
Wed Feb 18 05:15:32 EST 2009


Hello, communion people!

I have a little problem and ask for an advice. I'm trying to estimate the
performance speed of one pure function, but get some strange results.
-------------------------------------
import qualified module Data.ByteString.Lazy.Char8 as L8
import module Data.Digest.Pure.MD5
import module System.IO.Unsafe
import module System.Time
import module System.Random
import module Data.Char

clockTime2Tuple (TOD sec pic) = (sec, pic)
getClockTimeTuple = getClockTime >>= (\ x -> return $ clockTime2Tuple x)
subTimeTuples (s2,ps2) (s1,ps1) = let dps = ps2-ps1 in let (s,ps) =
(s2-s1-(if dps<0 then 1 else 0), if dps<0 then dps+(10^12) else dps) in (s,
(div) ps (10^6))

test_md5 test_input n = flip mapM test_input
        ( \ input_row -> do
                t1 <- getClockTimeTuple
                sequence_ (replicate n (return $ md5 input_row))
                t2 <- getClockTimeTuple 
                dt <- subTimeTuples t2 t1
                return (dt)
        )

test_list = 
[ pack "Hello world!"] ++ 
[L8.replicate 1000000 ':']
-------------------------------------
The results are (iterations_count, microseconds):
(1000,  [105,105]) (+/- 10)
(10000, [1000,950]) (+/- 50)
(100000, [9050,9000]) (+/- 50)
(1000000, [89200,89150]) (+/- 100)
-------------------------------------
I suspect following problems, which make the results non-objective:
1. I cant get out of laziness
2. I don't turn off GHC internal optimizers
So, perhaps, GHC evaluates the MD5 once, but cycles on something else?.. For
now I can only guess. Could anybody, please clarify and maybe suggest
configuration, which would allow objective speed estimation?

Thanks in advance,
Best regards,
Belka
-- 
View this message in context: http://www.nabble.com/estimating-the-speed-of-operation-tp22075843p22075843.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.



More information about the Haskell-Cafe mailing list