新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:pythontime模塊處理系統(tǒng)時(shí)間的函數(shù)
1、time.clock()

以秒為單位返回當(dāng)前CPU運(yùn)行時(shí)間,用于衡量不同程序的耗時(shí),比time.time()更實(shí)用。不過在python3.3之后就不推薦使用,原因是該方法依賴于操作系統(tǒng),官方建議使用per_counter(返回系統(tǒng)運(yùn)行時(shí)間)或process_time(返回進(jìn)程運(yùn)行時(shí)間)代替。
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()
返回當(dāng)前進(jìn)程執(zhí)行CPU的時(shí)間總和,不包含睡眠時(shí)間.由于返回值的基準(zhǔn)點(diǎn)是未定義的,所以只有連續(xù)調(diào)用的結(jié)果之間的差才是有效的。
print(time.process_time())#0.385954 time.sleep(5) print(time.process_time())#0.385982 time.sleep(secs)推遲調(diào)用線程的運(yùn)行,secs的單位是秒。如下所示: time.sleep(5)
以上就是python time模塊處理系統(tǒng)時(shí)間的函數(shù),希望能對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
文章名稱:創(chuàng)新互聯(lián)Python教程:pythontime模塊處理系統(tǒng)時(shí)間的函數(shù)
分享地址:http://m.fisionsoft.com.cn/article/ccooiii.html


咨詢
建站咨詢
