概述
由于时间模块提供了各种与时间有关的功能。因此,有必要导入时间模块,否则会出错,因为时间模块中存在perf_counter()的定义。
perf_counter()函数始终以秒为单位返回时间的浮点值。返回性能计数器的值(以分数秒为单位),即具有最高可用分辨率的时钟以测量短时间。它确实包括睡眠期间经过的时间,并且为system-wide。返回值的参考点是不确定的,因此仅连续调用结果之间的差有效。在这之间,我们可以使用time.sleep()和类似的功能。
代码1:了解perf_counter的用法。
# Python program to show time by perf_counter()
from time import perf_counter
# integer input from user, 2 input in single line
n, m = map(int, input().split())
# Start the stopwatch / counter
t1_start = perf_counter()
for i in range(n):
t = int(input()) # user gave input n times
if t % m == 0:
print(t)
# Stop the stopwatch / counter
t1_stop = perf_counter()
print("Elapsed time:", t1_stop, t1_start)
print("Elapsed time during the whole program in seconds:",
t1_
最后
以上就是曾经小土豆为你收集整理的python中perf_counter_Python time.perf_counter()用法及代码示例的全部内容,希望文章能够帮你解决python中perf_counter_Python time.perf_counter()用法及代码示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复