import time from functools import wraps def timer(func): @wraps(func) def inner(*args, **kwargs): start = time.time() res = func(*args, **kwargs) end = time.time() print("{0}运行耗时: {1:.2f}".format(func.__name__, end - start)) return res return inner @timer def counter(x): print("counter running!!!") time.sleep(3) return x x = counter(100) print(counter.__name__) print(x)