1、time.clock()
以秒为单位返回当前CPU运行时间,用于衡量不同程序的耗时,比time.time()更实用。不过在Python3.3之后就不推荐使用,原因是该方法依赖于操作系统,官方建议使用per_counter(返回系统运行时间)或process_time(返回进程运行时间)代替。
print(time.clock())#0.221209 #DeprecationWarning: time.clock has been deprecated in Python 3.3 and will be removed from Python 3.8: use time.perf_counter or time.process_time instead
2、time.process_time()
返回当前进程执行CPU的时间总和,不包含睡眠时间.由于返回值的基准点是未定义的,所以只有连续调用的结果之间的差才是有效的。
print(time.process_time())#0.385954 time.sleep(5) print(time.process_time())#0.385982 time.sleep(secs)推迟调用线程的运行,secs的单位是秒。如下所示: time.sleep(5)
以上就是python time模块处理系统时间的函数,希望能对大家有所帮助。更多Python学习指路:
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务