我是靠谱客的博主 忐忑飞机,这篇文章主要介绍python中使用time.pref_counter()精确计时,现在分享给大家,希望可以做个参考。

time.pref_counter()返回一个CPU级别的精确时间值,以秒为单位。
它通常用于测量某段程序的运行时间,因此取两次调用pref_counter()的差值才有意义。

import time

time_start = time.perf_counter()
for i in range(100000):
    a = 0
time_end = time.perf_counter()

time_consumed = time_end - time_start
print("耗费的时间: {} s".format(time_consumed))

耗费的时间: 0.0059451 s

最后

以上就是忐忑飞机最近收集整理的关于python中使用time.pref_counter()精确计时的全部内容,更多相关python中使用time内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(138)

评论列表共有 0 条评论

立即
投稿
返回
顶部