[Python-Dev] [RFC] PEP 418: Add monotonic time, performance counter and process time functions

Victor Stinner victor.stinner at gmail.com
Sun Apr 15 17:18:35 CEST 2012


> Here is a simplified version of the first draft of the PEP 418. The
> full version can be read online.
> http://www.python.org/dev/peps/pep-0418/

FYI there is no time.thread_time() function. It would only be
available on Windows and Linux. It does not use seconds but CPU
cycles. No module or program of the Python source code need such
function, whereas all other functions added by the PEP already have
users in the Python source code, see the Rationale section. For Linux,
CLOCK_THREAD_CPUTIME_ID is already available in Python 3.3. For
Windows, you can get GetThreadTimes() using ctypes or win32process.

> time.process_time()
> ^^^^^^^^^^^^^^^^^^^
>
> Pseudo-code [#pseudo]_::
>
>    if os.name == 'nt':
>        def process_time():
>            handle = win32process.GetCurrentProcess()
>            process_times = win32process.GetProcessTimes(handle)
>            return (process_times['UserTime'] +
> process_times['KernelTime']) * 1e-7
>    else:
>        import os
>        ...
>
>        def process_time():
>            ...
>            return _time.clock()

Is the C clock() function available on all platforms? timemodule.c
checks for HAVE_CLOCK, but test_time checks that time.clock() is
defined and does not fail since the changeset 4de05cbf5ad1, Dec 06
1996. If clock() is not available on all platforms,
time.process_time() documentation should be fixed.

Victor


More information about the Python-Dev mailing list