GetTickCount vs. clock for msec resolution

Dan Maas dmaas at nospam.dcine.com
Fri Apr 20 23:06:24 EDT 2001


>  clock() on
> Linux returns CPU time, not wall-clock time.  I don't remember what its
> resolution is, but you won't like it.  time.time() may or may not be
> better for you there (across Unix flavors, it varies from microsecond to
> full-second resolution; on Win9X it's something bizarre, *appearing* to
> be 10ms unless you look very carefully and notice it's only updated 18.2
> times per second).

That's right, most systems will not give you CPU time very accurately
because of the overhead it would involve (reading the CPU timer each 
context switch...)

On x86 Linux, time.time() reads the Pentium TSC (clock cycle counter), so
you get "wall-clock" time with a resolution of a few microseconds. (I put
"wall clock" in quotes because on SMP machines or systems that vary the
clock speed, you won't get a meaningful measurement...)

For profiling purposes, time.clock() is too coarse unless you run your
code for a LONG time. Personally I just use time.time(), and make sure
that Python is the only thing running on my system...

Dan



More information about the Python-list mailing list