# 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'