python time.monotonic()方法,获取单调时钟

time.monotonic()方法

python time模块monotonic()方法,可以获取单调时钟。而什么是单调时钟呢?这是一种不需要跟用户端、服务器或其它外部时间源进行同步的,且无法回拨的时钟,更适合用于统计持续的时间间隔,比如统计服务器响应时间、超时时间等等。


语法

monotonic() -> float

python源码中对monotonic()方法的介绍:

    Monotonic clock, cannot go backward.

参数

无。


返回值

python语法中“->”符号已经指定了monotonic()方法的返回值类型为float浮点数类型。


monotonic()实例代码

>>> import time
>>> time.monotonic()
265439.611848345
>>> time.monotonic() #单调时钟无法回拨,所以后一次调用的返回值比前者大。
265446.64360358

全栈后端 / Python库 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.