描述
Pythom時間法clock()將當前處理器時間返回為以秒表示的浮點數Unix.精度取決於同名 C 函數的精度,但無論如何,這是用於對 Python 或計時算法進行基準測試的函數。
在Windows,此函數根據 Win32 函數 QueryPerformanceCounter 以浮點數形式返回自第一次調用此函數以來經過的 wall-clock 秒。
用法
以下是語法clock()方法≫
time.clock()
參數
NA
返回值
此方法以浮點數形式返回當前處理器時間,在 Unix 上以秒表示,在 Windows 中,它以浮點數形式返回自第一次調用此函數以來經過的 wall-clock 秒。
示例
下麵的例子展示了 clock() 方法的用法。
#!/usr/bin/python
import time
def procedure():
time.sleep(2.5)
# measure process time
t0 = time.clock()
procedure()
print time.clock(), "seconds process time"
# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"
當我們運行上麵的程序時,它會產生以下結果——
0.0 seconds process time 2.50023603439 seconds wall time
注意- 並非所有係統都可以測量真正的過程時間。在此類係統(包括 Windows)上,時鍾通常測量自程序啟動以來的牆上時間。
相關用法
- Python time ctime()用法及代碼示例
- Python time mktime()用法及代碼示例
- Python time localtime()用法及代碼示例
- Python time sleep()用法及代碼示例
- Python time strftime()用法及代碼示例
- Python time asctime()用法及代碼示例
- Python time altzone()用法及代碼示例
- Python time tzset()用法及代碼示例
- Python time time()用法及代碼示例
- Python time replace()用法及代碼示例
- Python time gmtime()用法及代碼示例
- Python time strptime()用法及代碼示例
- Python time.monotonic()用法及代碼示例
- Python time.asctime()用法及代碼示例
- Python time.ctime()用法及代碼示例
- Python time.perf_counter()用法及代碼示例
- Python time.get_clock_info()用法及代碼示例
- Python time.gmtime()用法及代碼示例
- Python time.time()用法及代碼示例
- Python time.mktime()用法及代碼示例
注:本文由純淨天空篩選整理自 Python time clock() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。