Even though they are deprecated and there is a better module than time
(i.e timeit
), I would like to know the differences between the two functions time.clock()
and time.time()
.
Starting from the latter (time.time()
), it basically returns the time elapsed from the 01/01/1970 (if I am not wrong) in seconds with a precision, in general, of 1 second. 'Till here it's easy.
Instead, time.clock()
still makes me confused.
From the doc:
On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor 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.
On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.
Now in Windows it's pretty clear, it does what time.time()
does, only with a better precision.
But in Unix/Linux I can't understand. I tried the following code:
import time
def procedure():
time.sleep(2.5)
# measure process time
t0 = time.clock()
procedure()
print(time.clock() - t0, "process time")
and I got 5.300000000000096e-05 seconds process time
which was really wierd to me.
Reading this already-posted question an answer says:
[...] time.clock() measures the amount of CPU time that has been used by the current process.
But I can't get it, the time used by the current process in doing what? When I call time.clock()
on Unix I get a float number, what does that mean in that instant? The amout of time consumed by the process from ?? to ??