pythontime模塊處理系統時間的函數
1、time.clock()
以秒為單位返回當前CPU運行時間,用于衡量不同程序的耗時,比time.time()更實用。不過在Python3.3之后就不推薦使用,原因是該方法依賴于操作系統,官方建議使用per_counter(返回系統運行時間)或process_time(返回進程運行時間)代替。
print(time.clock())#0.221209
#DeprecationWarning:time.clockhasbeendeprecatedinPython3.3andwillberemovedfromPython3.8:usetime.perf_counterortime.process_timeinstead
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)
以上就是pythontime模塊處理系統時間的函數,希望能對大家有所幫助。更多Python學習教程請關注IT培訓機構:千鋒教育。