Know the code execution time
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
}
}
'''
Recommended Posts