[Python-checkins] peps: PEP 418: time.process_time() uses CLOCK_PROF if available
victor.stinner
python-checkins at python.org
Wed Apr 18 01:34:29 CEST 2012
http://hg.python.org/peps/rev/438a9af89329
changeset: 4263:438a9af89329
user: Victor Stinner <victor.stinner at gmail.com>
date: Wed Apr 18 01:34:26 2012 +0200
summary:
PEP 418: time.process_time() uses CLOCK_PROF if available
files:
pep-0418.txt | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/pep-0418.txt b/pep-0418.txt
--- a/pep-0418.txt
+++ b/pep-0418.txt
@@ -134,7 +134,7 @@
if os.name == 'nt':
# GetTickCount64() requires Windows Vista, Server 2008 or later
- if hasattr(time, '_GetTickCount64'):
+ if hasattr(_time, '_GetTickCount64'):
def monotonic():
return _time.GetTickCount64() * 1e-3
else:
@@ -237,11 +237,11 @@
has_resource = True
def process_time():
- if process_time.use_process_cputime:
+ if process_time.clock_id is not None:
try:
- return time.clock_gettime(time.CLOCK_PROCESS_CPUTIME_ID)
+ return time.clock_gettime(process_time.clock_id)
except OSError:
- process_time.use_process_cputime = False
+ process_time.clock_id = None
if process_time.use_getrusage:
try:
usage = resource.getrusage(resource.RUSAGE_SELF)
@@ -256,9 +256,14 @@
except OSError:
process_time.use_getrusage = False
return _time.clock()
- process_time.use_process_cputime = (
- hasattr(time, 'clock_gettime')
- and hasattr(time, 'CLOCK_PROCESS_CPUTIME_ID'))
+ if (hasattr(time, 'clock_gettime')
+ and hasattr(time, 'CLOCK_PROF')):
+ process_time.clock_id = time.CLOCK_PROF
+ elif (hasattr(time, 'clock_gettime')
+ and hasattr(time, 'CLOCK_PROCESS_CPUTIME_ID')):
+ process_time.clock_id = time.CLOCK_PROCESS_CPUTIME_ID
+ else:
+ process_time.clock_id = None
process_time.use_getrusage = has_resource
process_time.use_times = hasattr(_time, 'times')
if process_time.use_times:
--
Repository URL: http://hg.python.org/peps
More information about the Python-checkins
mailing list