import time
import textwrap
the_clocks = [
('clock', time.clock),
('monotonic', time.monotonic),
('perf_counter', time.perf_counter),
('process_time', time.process_time),
('time', time.time),]
for clock_name, function in the_clocks:
print(textwrap.dedent('''{name}:
adjustable : {info.adjustable}
implementation: {info.implementation}
monotonic : {info.monotonic}
resolution : {info.resolution}
current : {current}''').format(name=clock_name, info=time.get_clock_info(clock_name), current=function())
)
'''
run:
clock:
adjustable : False
implementation: clock()
monotonic : True
resolution : 1e-06
current : 0.042364
monotonic:
adjustable : False
implementation: clock_gettime(CLOCK_MONOTONIC)
monotonic : True
resolution : 1e-09
current : 4486722.66659043
perf_counter:
adjustable : False
implementation: clock_gettime(CLOCK_MONOTONIC)
monotonic : True
resolution : 1e-09
current : 4486722.666622312
process_time:
adjustable : False
implementation: clock_gettime(CLOCK_PROCESS_CPUTIME_ID)
monotonic : True
resolution : 1e-09
current : 0.042480553000000004
time:
adjustable : True
implementation: clock_gettime(CLOCK_REALTIME)
monotonic : False
resolution : 1e-09
current : 1559417939.157021
'''