9
8

More than 1 year has passed since last update.

[Python][Tips] 処理時間の計測

Last updated at Posted at 2022-09-28

上記によると、Python処理の実行時間を測定する方法は以下の3つ。

(1) time.time() : 最も簡単な実行時間を測定する方法
(2) time.perf_counter() : 正確に実行時間を測定する方法
(3) time.process_time() : CPU実行時間のみを測定する方法(sleep時間を除く)

(2)が実用的に使えるので、実際の業務で利用しています。

import time

start = time.perf_counter() #計測開始
##################################
#####                        #####
#####    計測したい処理を実行    #####
#####                        #####
#################################
end = time.perf_counter() #計測終了
print('{:.2f}'.format((end-start)/60)) # 87.97(秒→分に直し、小数点以下の桁数を指定して出力)
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8