'''
time.sleep(secs)
参数:
secs:推迟执行的秒数
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
'''
time.sleep(1)
'''
time.time()
无参数
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
'''
start = time.time()print(start)# 1720171791.0012453
1.3、time.time_ns()
方法
描述
time.time_ns()
获取当前的纳秒级时间戳
'''
time.time_ns()
无参数
Return the current time in nanoseconds since the Epoch.
'''
start = time.time_ns()print(start)# 1720406402195668200
'''
time.process_time()
无参数
Process time for profiling: sum of the kernel and user-space CPU time.
'''
start_time = time.process_time()
time.sleep(1)# 不计算list=[i for i inrange(2**20)]
end_time = time.process_time()print("程序执行时间为:{} - {} = {}".format(end_time, start_time, end_time - start_time))# 程序执行时间为:0.046875 - 0.03125 = 0.015625
1.6、time.thread_time()
方法
描述
time.process_time()
当前线程的系统和用户CPU时间之和的值(以秒为单位)。
'''
time.process_time()
无参数
Thread time for profiling: sum of the kernel and user-space CPU time.
'''import time
start_time = time.thread_time()
time.sleep(1)# 不计算list=[i for i inrange(2**20)]
end_time = time.thread_time()print("程序执行时间为:{} - {} = {}".format(end_time, start_time, end_time - start_time))# 程序执行时间为:0.046875 - 0.03125 = 0.015625