实例1
复制代码
1
2
3
4
5
6
7
8
9
10import time limit = 10*100*1000 start = time.perf_counter() while True: limit -= 1 if limit <= 0: break delta = time.perf_counter() - start print("程序运行的时间是:{}秒".format(delta))
在本人计算机配置下输出为:
复制代码
1程序运行的时间是:0.08018969999999999秒
实例2
复制代码
1
2
3
4
5
6
7
8
9
10import time time.sleep(1) a=time.perf_counter()#第一次调用per_counter,所以a值应该为零,但是他不是刚好为零 print(a) print(round(a))#把a四舍五入验证下 print(type(a))#验证a是浮点数 time.sleep(5) b=time.perf_counter()#sleep5秒后,b的值就应该是5 print(b)
输出为:
复制代码
1
2
3
43e-07 0 <class 'float'> 5.0016937
最后
以上就是清新马里奥最近收集整理的关于Python 程序运行计时 计时器 time.perf_counter()的全部内容,更多相关Python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复