time.clock() or time.time()

Leonhard Vogt leonhard.vogt at gmx.ch
Tue Aug 2 12:33:31 EDT 2005


peterbe at gmail.com schrieb:
> What's the difference between time.clock() and time.time()
> (and please don't say clock() is the CPU clock and time() is the actual
> time because that doesn't help me at all :)

clock (depending on the platform ?) measures the time spent by your program.

Time gives you the system time, so the difference is the time between
your calls, your program could have been idle (waiting for input or
sharing processor due to multitasking)

> I'm trying to benchmark some function calls for Zope project and when I
> use t0=time.clock(); foo(); print time.clock()-t0
> I get much smaller values than when I use time.clock() (most of them
> 0.0 but some 0.01)

Run your code 100 times and divide the result by 100.

Leonhard



More information about the Python-list mailing list