import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))
from datetime import datetime
startTime = datetime.now()
#do something
#Python 2:
print datetime.now() - startTime
#Python 3:
print(datetime.now() - startTime)
#its tricky and so much easy
#python execute time counter
#coded by Luban
import time
start_time = time.time()
while True:
x = time.time() - start_time
x = int(x)
print('Current Time = ',str(x))
# python code execution time -- using wrapper
import time
def exec_time(func):
def wrapper():
start_time = time.time()
result = func()
elapsed = time.time() - start_time
return elapsed, result
return wrapper
@exec_time
def hlw():
time.sleep(2)
return "hello"
t, o = hlw()
print(t, o) # 2.001209020614624 'hello'