2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

めざせpythonライブラリマスター (52)marktime

Posted at

#【ライブラリ説明】
 コードの実行時間が分かる

#【プログラム】

marktime.py
# -*- coding: utf-8 -*-


import marktime
import json

marktime.start('some task')

x = []

for i in xrange(10000000):
    x.append(i)

print marktime.stop('some task').seconds
# 1.73500013351

marktime.start('some another task')

y = 0
for i in xrange(10000000):
    y += i

print marktime.stop('some another task').seconds
# 1.67599987984


marktime.start('some task # 3')

with marktime.stopwatch('some task # 4'):
    marktime.time.sleep(1)

print json.dumps(marktime.labels, indent=4)
'''
{
    "some another task": {
        "duration": 1.6759998798370361, 
        "start_time": 1465628428.266, 
        "end_time": 1465628429.942
    }, 
    "some task # 3": {
        "start_time": 1465628429.942, 
        "end_time": null
    }, 
    "some task # 4": {
        "duration": 1.00600004196167, 
        "start_time": 1465628429.942, 
        "end_time": 1465628430.948
    }, 
    "some task": {
        "duration": 1.7350001335144043, 
        "start_time": 1465628426.531, 
        "end_time": 1465628428.266
    }
}
'''

#【参考サイト】
 pypi
 github

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?