wasm-demo/demo/ermis-f/python_m/cur/0361

85 lines
3.2 KiB
Plaintext

From: sdm7g at Virginia.EDU (Steven D. Majewski)
Date: Fri, 23 Apr 1999 14:59:31 -0400 (EDT)
Subject: millisecond time accuracy
In-Reply-To: <14112.46141.974182.785300@amarok.cnri.reston.va.us>
References: <3720A4A6.125DA1C7@OMIT_THIS.us.ibm.com> <14112.46141.974182.785300@amarok.cnri.reston.va.us>
Message-ID: <Pine.A32.3.90.990423143116.23052F-100000@elvis.med.Virginia.EDU>
Content-Length: 2827
X-UID: 361
On Fri, 23 Apr 1999, Andrew M. Kuchling wrote:
> Kevin F. Smith writes:
> >Is there a way to measure time accurate to milliseconds?
> >
> >For example, by calling the time.time() function I get seconds. Is
> >there a comparable function that I could use to measure interval times
> >down to at least millisecond accuracy?
>
> Nothing portable. However, time.time() actually returns a
> floating point number, and the Python implementation tries to use the
> most precise function available in the C library. If your system
> supports gettimeofday(), which has microsecond resolution, then
> time.time() will return a floating point number with microsecond
> precision.
>
> Note that precision is not the same as accuracy! Python just
> uses the C library, so the accuracy or lack thereof is up to the
> library implementation.
>
I was having problems using time.time for benchmarking on the Mac,
and was complaining to Jack about it returning integral number of
seconds converted to a Python float, when I noticed in the Lib ref:
<http://www.python.org/doc/lib/module-time.html>
clock ()
Return the current CPU time as a floating point number expressed in
seconds. The precision, and in fact the very definiton of the meaning of
``CPU time'', depends on that of the C function of the same name, but in
any case, this is the function to use for benchmarking Python or timing
algorithms.
i.e. time.clock() is supposed to be the best precision you can get.
Now -- I'm not sure that is actually the case, but on the Mac
time.clock() - time.clock() has a significant fractional part, while
time.time() - time.time() doesn't.
( The offsets of the number of seconds returned by time and clock
are different, which is why I'm expressing the value as difference
of two pairs. )
On Mac Python, the resolution is 1/60 sec., however it's possible
to get much better resolution by uncommenting a line(*) and rebuilding
the C libraries, however, Jack was suggesting exporting an additional
time.Microseconds() function.
What I want is a standard & portable way of getting the best clock value
on whatever platform.
(*) note:
> > [1.5] discovered in :MSL C:MSL Mac:Public Includes:timesize.mac.h
> > that you can enable microsecond resolution by uncommenting:
> > #define __TIMESIZE_DOUBLE__
> > which causes clock_t to be a double and redefines CLOCKS_PER_SEC.
---| Steven D. Majewski (804-982-0831) <sdm7g at Virginia.EDU> |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---
Caldera Open Linux: "Powerful and easy to use!" -- Microsoft(*)
(*) <http://www.pathfinder.com/fortune/1999/03/01/mic.html>