PEP 418: Write the pseudo-code of time.time()
This commit is contained in:
parent
ee094d5cb9
commit
ae01ce94ad
27
pep-0418.txt
27
pep-0418.txt
|
@ -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()
|
||||
----------------
|
||||
|
|
Loading…
Reference in New Issue