From: Fei Xia
Subject: help: how to time a function?
Date: 
Message-ID: <4fu1qt$871@netnews.upenn.edu>
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? 


Thanks in advance.


-Fei

From: Stephan Kepser
Subject: Re: help: how to time a function?
Date: 
Message-ID: <4fv4k5$4bi@sparcserver.lrz-muenchen.de>
In article <··········@netnews.upenn.edu> ····@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? 
> 
> 
> Thanks in advance.
> 
> 
> -Fei

You can make timing easier using (time form) [p 696 in CLtL2], that saves  
you some computations ["form" is the Lisp form you want to time]. In order  
to get a better precision, just call the function not just once but  
several (thousand) times and divide the result by the number of calls. It  
has the added advantage of calcualting an average over system  
fluctuations. A call my look like that
(time (dotimes (i 1000) form))
In order to get rid of the time needed for DOTIMES, you can
(time (dotimes (i 1000)))
and subtract the result from the previous one.

Hope that helps.

Stephan.

--
Stephan Kepser           ······@thecube.cis.uni-muenchen.de
CIS   Centrum fuer Informations- und Sprachverarbeitung
LMU Muenchen, Wagmuellerstr. 23/III, D-80538 Muenchen,  Germany
Tel: +49 +89/2110666     Fax: +49 +89/2110674
From: Marty Hall
Subject: Re: help: how to time a function?
Date: 
Message-ID: <Dn14st.AD5@aplcenmp.apl.jhu.edu>
In <··········@netnews.upenn.edu> ····@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))