perf_counter()函数——time.perf_counter()

time.perf_counter()

自我理解

  • perf_counter()是第三方库time的函数
  • perf_counter()返回当前的计算机系统时间
  • 只有连续两次perf_counter()进行差值才能有意义,一般用于计算程序运行时间。
import time
start = time.perf_counter()
time.sleep(5)
end = time.perf_counter()
dur = start - end
print(dur)

使用sleep让程序休眠5s,dur就是程序运行消耗的时间。

1、Dash中函数说明

  • time.perf_counter() → float
    Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It does include time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.
  • 返回值为float类型
  • 返回计数器的值(以微秒为单位),即最高测量分辨率的时钟。包括睡眠时间和系统时间。返回值的引用点未定义,因此只有连续调用结果之间的差异才有效。

2、标准库中定义

def perf_counter(): # real signature unknown; restored from __doc__
    """
    perf_counter() -> float
    
    Performance counter for benchmarking.
    """
    return 0.0
  • 25
    点赞
  • 71
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值