Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsxfer2.itd.umich.edu!chi-news.cic.net!newsspool.doit.wisc.edu!night.primate.wisc.edu!aplcenmp!hall
From: hall@aplcenmp.apl.jhu.edu (Marty Hall)
Subject: Re: help: how to time a function?
Message-ID: <Dn14st.AD5@aplcenmp.apl.jhu.edu>
Organization: JHU/APL Research Center, Hopkins P/T CS Faculty
References: <4fu1qt$871@netnews.upenn.edu>
Date: Mon, 19 Feb 1996 15:38:53 GMT
Lines: 30

In <4fu1qt$871@netnews.upenn.edu> fxia@linc.cis.upenn.edu (Fei Xia) writes:
>I used (get-internal-run-time) to time my function. But since its
>precision is only 0.01 seconds, I always get 0. Can anybody tell
>me how to improve the precision? 

On most systems with which I am familiar, the builtin TIME procedure
yields precision no better than that of GET-INTERNAL-RUN-TIME. So
using TIME will not help you. What I generally do is to use a macro
that expands (Foo X Y Z) into many repeated calls to (Foo X Y Z) then
averages the time by the number of calls. It does the expansion into
multiple calls at compile time, not at run time (as a loop would do),
so it works even for relatively short/fast functions. However, this
obviously fails if (Foo X Y Z) does some side effect like sorting an
array, as each subsequent call won't be the same. In this latter case
I also have some macros that help, but are not as accurate.

Both of these are available from 
http://www.apl.jhu.edu/~hall/lisp.html under the "Simple
Timing/Metering" heading. There are also some PostScript notes on the
same page giving hints on benchmarking Lisp applications and giving
links to some of Ken Anderson's stuff in this area.

To risk stating the obvious, don't forget to use your implementation's
builtin profiler on some large but representative sample cases. I have
a very rudimentary interface to the profiler of Lucid, Allegro, and
LispWorks in the same file mentioned above.

Cheers-
						- Marty
(proclaim '(inline skates))
