python記錄程式執行時間的兩種方法

2021-09-21 13:35:53 字數 580 閱讀 8118

import time

start = time.perf_counter() //起始時間

x=10

y=x*x*x //要執行的**塊

end = time.perf_counter() //結束時間

print('%.10f'%(end - start)) //輸出執行時間,精確到小數點後十位

使用python自帶的time庫記錄程式執行的起始和結束時間

import cv2

start = cv2.gettickcount() //起始時間

x=10

y=x*x*x //**塊

end = cv2.gettickcount() //結束時間

t='%.10f'%((end-start)/cv2.gettickfrequency()) //時間間隔除以週期,換算成秒為單位

print(t)

呼叫opencv中的時間函式記錄時間

python記錄程式執行時間

方法1 import datetime starttime datetime.datetime.now long running endtime datetime.datetime.now print endtime starttime seconds 方法 2 start time.time ru...

巨集 記錄程式執行時間

經常遇到一些情況,需要計算 執行的效率,所以要進行多次迴圈得到,用得多了,就發現把這段 封裝起來很合適,且很實用。如下 cctime.h c common codes created by xichen on 12 2 18.ifndef cc time h define cc time h inc...

記錄執行時間

記錄乙個在device上執行的函式的執行時間時需要用到 事件 event cudaevent t timestartevent,timeendevent 宣告兩個cudaevent t變數 cudaeventcreate tartevent,0 第二個引數忘了幹嗎用的了 cudaeventcreat...