214
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

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

はじめに

以前書いた『【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のときと同じです。
基本的に
(処理時間)=(処理が終わった時間)ー(処理を始めた時間)
というアルゴリズムは変わらないので(^^;)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
214
Help us understand the problem. What are the problem?