import time
from functools import wraps
def get_running_time(func):
# 使用wraps, 保证被装饰过的函数__name__的属性不变
@wraps(func)
def inner(*args, **kwargs):
start_time = time.time()
# print(start_time)
res = func(*args, **kwargs)
end_time = time.time()
# print(end_time)
print('the running time is {}'.format(end_time - start_time))
return res
return inner
python --- output function of time decorator
Guess you like
Origin www.cnblogs.com/KX-Lau/p/12461642.html
Recommended
Ranking