借助time.perf_counter()提高时间测量精度
time.perf_counter()函数提供了高精度的计时器,适合用于性能测试和计时。使用它记录开始和结束时间,再计算两者间差值,精度优于time.time(),示例如下:
import time
start = time.perf_counter()
代码块
end = time.perf_counter()
print('高精度运行时间:', end - start, '秒')
借助time.perf_counter()提高时间测量精度
time.perf_counter()函数提供了高精度的计时器,适合用于性能测试和计时。使用它记录开始和结束时间,再计算两者间差值,精度优于time.time(),示例如下:
import time
start = time.perf_counter()
代码块
end = time.perf_counter()
print('高精度运行时间:', end - start, '秒')