Timing repeated function calls

Jeffrey A. Scofield sja10587@qwest.net
Fri, 8 Aug 2003 12:30:40 -0700

Ketil Z. Malde wrote:

>> 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).
> No chance you could call it with different parameters each time?

I will try this--thanks very much for the suggestion.  (However,
the parameters won't have any effect, and I worry that the compiler
will figure this out!)

> Another question is why you want to do this.  If you're worried your
> function will consume too much time in some application, surely
> profiling will get you better and more accurate information?

I'm not worried about speed per se, rather I'm trying to validate
my (rough) complexity analysis for the function and, if it works,
to make some projections for how long it would take to calculate
various things.  Unfortunately, the time grows fairly fast with n,
so I would like to have good measurements for small n where the
time is quite small (hundredths of a second per call).  In my
past life (imperative programmer), the way to do this is to call
the function lots of times.

(If anyone is interested, I can show my code.  What it does is
search for perfect numbers by calculating prime factors for all
integers up to a chosen maximum.  The problem is that the size
of the nth perfect number increases amazingly fast with n.)