python 裝飾器統計某個函數的運行時間
阿新 • • 發佈:2018-04-15
seconds 結束 code UNC sta star %s range __name__
import datetime def count_time(func): def int_time(*args, **kwargs): start_time = datetime.datetime.now() # 程序開始時間 func() over_time = datetime.datetime.now() # 程序結束時間 total_time = (over_time-start_time).total_seconds() print(‘程序共計%s秒‘ % total_time)return int_time @count_time def main(): print(‘>>>>開始計算函數運行時間‘) for i in range(1, 1000): for j in range(i): print(j) if __name__ == ‘__main__‘: main()
python 裝飾器統計某個函數的運行時間