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

相关文章:

  • 2022-12-23
  • 2021-09-01
  • 2022-12-23
  • 2021-09-19
  • 2021-07-14
猜你喜欢
  • 2022-12-23
  • 2021-10-29
  • 2021-12-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
相关资源
相似解决方案