示例代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import time def run_time(func): """计算程序运行时间的函数""" start_time = time.time() func() end_time = time.time() print("程序一共执行了%s" % (end_time - start_time) + '秒') def func(): """求阶乘的函数""" x = 1 for i in range(1,10000): x *= i print(x) def foo(): """程序睡眠的函数""" print("hello") time.sleep(3) print('world') # 调用函数,并将这些函数当作参数传入到计时函数中 run_time(func) run_time(foo)