Python 装饰器:
import time def foo(): print("foo.....") time.sleep(2) def bar(): print("bar...") time.sleep(3) def show_time(f): start = time.time() f() end = time.time() print("spend %s" % (end-start)) show_time(foo) show_time(bar)