PEP 418: Write the pseudo-code of time.time()

This commit is contained in:
Victor Stinner 2012-03-27 19:34:04 +02:00
parent ee094d5cb9
commit ae01ce94ad
1 changed files with 24 additions and 3 deletions

View File

@ -62,11 +62,32 @@ The system time is the "wall clock". It can be set manually by the system
administrator or automatically by a NTP daemon. It can jump backward and
forward, and is not monotonic.
* Windows: GetSystemTimeAsFileTime()
* clock_gettime(CLOCK_REALTIME), gettimeofday(), ftime() or time()
It is avaialble on all platforms and cannot fail.
Pseudo-code::
if os.name == "nt":
def time():
return _time.GetSystemTimeAsFileTime()
elif hasattr(time, "clock_gettime") and hasattr(time, "CLOCK_REALTIME"):
def time():
# resolution = 1 nanosecond
return time.clock_gettime(time.CLOCK_REALTIME)
else:
def time():
if hasattr(_time, "gettimeofday"):
try:
# resolution = 1 microsecond
return _time.gettimeofday()
except OSError:
pass
if hasattr(_time, "ftime"):
# resolution = 1 millisecond
return _time.ftime()
else:
# resolution = 1 second
return _time.time()
time.monotonic()
----------------