Python Forum
time.process_time() is constant - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: time.process_time() is constant (/thread-20506.html)



time.process_time() is constant - redglyph - Aug-14-2019

Hello!

I'm usually using time.clock() to measure the time elapsed in a process, to disregard time spent in other processes (so not the 'wall clock').

I see that it is deprecated (because "The problem is time.clock(), since it does two wildly different things depending on the OS"...) and about to be removed in 3.8, and that time.process_time() is to be used instead.

I am currently testing it on Python 3.7.4 (64-bit) for Windows, on Win7 x64, and the returned value of time.process_time() is always the same, thus the elapsed time is always zero.

>>> time.process_time()
0.0936006
>>> time.sleep(3)
>>> time.process_time()
0.0936006
Is that a known issue, or am I doing something wrong? I searched but didn't find anything relevant.

I'm aware that time.clock() was not always returning the process elapsed time in Windows, but may return the actual elapsed time, and that this should mostly be used with Linux implementation. Still, I'm not expecting that new function to return a constant value.


RE: time.process_time() is constant - redglyph - Aug-14-2019

Obviously it doesn't get the same precision as Linux. Using another, more time-consumming task between the measures show a difference.