import time
def echo_runtime(func):
def wrapper(*args, **kwargs):
start_time = time.time()
res = func(*args, **kwargs)
end_time = time.time()
print(func.__name__ + " running time is %.6f s" % (end_time - start_time))
return res
return wrapper
@echo_runtime
def test_fun():
print('this is a test fun')
time.sleep(5)
if __name__ == '__main__':
test_fun()
# test_fun running time is 5.00 s