Timing repeated function calls

Jeffrey A. Scofield sja10587@qwest.net
Thu, 7 Aug 2003 23:41:42 -0700


Using GHC 6.0 on Mac OS X (10.2.6), I'm trying to do some timing
tests of something that doesn't take very long.  So, I want to call
a function repeatedly (1000s of times).  It appears, however, that
the compiler is figuring out that there's no need to call the
function more than once since it's pure.

Is there anything simple I can do to get the compiler to call a
function repeatedly?

Here is a snippet of code showing what I am trying right now:

     main = do
         t0 <- getClockTime
         times 1000
         t1 <- getClockTime
         . . .

     times :: Int -> IO ()
     times 0 = return ()
     times n = do
         let [a,b,c,d] = take 4 (myFunction)
         Control.Exception.evaluate a
         Control.Exception.evaluate b
         Control.Exception.evaluate c
         Control.Exception.evaluate d
         times $! n - 1

     myFunction :: [Int]
     myFunction = . . .

(There may be some absurd stuff in this code;  I've left in the
remnants of several failed attempts.)


Jeff Scofield