2020年5月7日 星期四

Python,測量程式碼執行時間

# 引入 datetime 模組
import datetime

# 開始測量
start = datetime.datetime.now()

# 要測量的程式碼
for i in range(10000):
    "-".join(str(n) for n in range(100))

# 結束測量
end = datetime.datetime.now()

# 輸出結果
print("執行時間:", end - start)


--------------------------------------------------------------------------------------
https://officeguide.cc/python-measure-execution-time-tutorial-examples/

沒有留言:

張貼留言