#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 可监控程序运行时间
import time
def clock(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print("共耗时: %s秒" % round(end_time - start_time, 2))
return result
return wrapper
# 使用局部变量
@clock
def multiplication():
size = 10000
for x in range(size):
for y in range(size):
z = x * y
multiplication()
# 共耗时: 5.5秒,提速50%
【Python】程序监控
最新推荐文章于 2024-11-02 16:28:26 发布