time.clock() always returns 0?

Thomas Wouters thomas at xs4all.net
Sun Jun 11 08:41:45 EDT 2000


On Sun, Jun 11, 2000 at 08:31:34AM -0400, Doug Fort wrote:

> On my system (RedHat Linux 6.2 Python 1.5.2 as shipped with RedHat)
> time.clock() always returns 0.  time.time() returns a good value.  Is this
> known behavior?  Am I doing something wrong?

What do you think time.clock() does ? The docstring says this:

clock() -> floating point number

Return the CPU time or real time since the start of the process or since the
first call to clock().  This has as much precision as the system records.

Notice how it says 'or since the first call to clock()'. Notice also how it
says it has as much precision as the system records -- if your Linux system
for some reason isn't keeping proper records, you wont get proper results.
If you need better results, os.times() may be what you need:

times() -> (utime, stime, cutime, cstime, elapsed_time)
Return a tuple of floating point numbers indicating process times.

Then again, if you need what time.time() returns, you do not need
time.clock() :-)

-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list