time.time or time.clock
Ron Adam
rrr at ronadam.com
Sun Jan 13 23:08:39 EST 2008
Fredrik Lundh wrote:
> John Machin wrote:
>
>> AFAICT that was enough indication for most people to use time.clock on
>> all platforms ...
>
> which was unfortunate, given that time.clock() isn't even a proper clock
> on most Unix systems; it's a low-resolution sample counter that can
> happily assign all time to a process that uses, say, 2% CPU and zero
> time to one that uses 98% CPU.
>
> > before the introduction of the timeit module; have you considered it?
>
> whether or not "timeit" suites his requirements, he can at least replace
> his code with
>
> clock = timeit.default_timer
>
> which returns a good wall-time clock (which happens to be time.time() on
> Unix and time.clock() on Windows).
Thanks for the suggestion Fredrik, I looked at timeit and it does the
following.
import sys
import time
if sys.platform == "win32":
# On Windows, the best timer is time.clock()
default_timer = time.clock
else:
# On most other platforms the best timer is time.time()
default_timer = time.time
I was hoping I could determine which to use by the values returned. But
maybe that isn't as easy as it seems it would be.
Ron
More information about the Python-list
mailing list