LoginSignup
340
212

More than 5 years have passed since last update.

【Python】処理にかかる時間を計測して表示

Last updated at Posted at 2014-10-20

はじめに

以前書いた『【PHP】処理にかかる時間を計測して時間・分・秒で表示』という記事がまぁまぁ反響があったので今回はPythonで。

サンプルコード

hoge.py
#-*- using:utf-8 -*-
import time

if __name__ == '__main__':
    start = time.time()
    for i in range(0,11):
        print "a"
    elapsed_time = time.time() - start
    print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

まぁ、やっていることはほとんどPHPのときと同じです。
基本的に
(処理時間)=(処理が終わった時間)ー(処理を始めた時間)
というアルゴリズムは変わらないので(^^;)

340
212
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
340
212