Python| time.get_clock_info() 方法
Python中的时间模块提供了各种与时间相关的功能。
Time 模块中的time.get_clock_info()
方法用于获取指定时钟名称的信息。此方法将信息作为命名空间对象返回。
支持的时钟名称和读取该时钟值的方法如下:
- 时钟:
time.clock()
- 单调:
time.monotonic()
- perf_counter :
time.perf_counter()
- process_time :
time.process_time()
- 线程时间:
time.thread_time()
- 时间:时间。时间
time.time()
Syntax: time.get_clock_info(name)
Parameter:
name: A string value representing the clock name.
Return type: This method returns a namespace object whose attributes represents the information about specified clock name.
Following are the attributes of namespace object:
- adjustable: This is ‘True’ if the clock can be changed automatically or manually by the system administrator. Otherwise ‘False’.
- implementation: The name of the underlying C function used to get the clock value.
- monotonic: It’s value is true, if the clock can not go backward. Otherwise False.
- resolution: This attribute specify the resolution of clock in seconds.
代码: time.get_clock_info()
方法的使用
# Python program to explain time.get_clock_info() method
# importing time module
import time
# Clock name
clock_name = 'clock'
# Get the information on
# the specified clock name
clock_info = time.get_clock_info(clock_name)
# Print the information
print("Information on '% s':" % clock_name)
print(clock_info)
clock_name = 'perf_counter'
# Get the information on
# the specified clock name
clock_info = time.get_clock_info(clock_name)
# Print the information
print("\nInformation on '% s':" % clock_name)
print(clock_info)
clock_name = 'process_time'
# Get the information on
# the specified clock name
clock_info = time.get_clock_info(clock_name)
# Print the information
print("\nInformation on '% s':" % clock_name)
print(clock_info)
输出:
Information on 'clock':
namespace(adjustable=False, implementation='clock()',
monotonic=True, resolution=1e-06)
Information on 'perf_counter':
namespace(adjustable=False, implementation='clock_gettime(CLOCK_MONOTONIC)',
monotonic=True, resolution=1e-09)
Information on 'process_time':
namespace(adjustable=False, implementation='clock_gettime(CLOCK_PROCESS_CPUTIME_ID)',
monotonic=True, resolution=1e-09)
参考: https://docs。 Python.org/3/library/time.html#time.get_clock_info