用一个装饰器,监控程序的运行时间
import time
def count_time(func):
def int_time(*args, **kwargs):
start_time = time.time() # 程序开始时间
func()
over_time = time.time() # 程序结束时间
total_time = over_time - start_time
print('程序共计%s秒' % total_time)
return int_time
@count_time
def main():
print('>>>>开始计算函数运行时间')
x = 0
for i in range(1000000):
x=x//13
print(x)
if __name__ == '__main__':
main()