import time
defcalTime(func):deffun():
start = time.time()
func()
end = time.time()print("程序运行时间为{}".format(end-start))return fun
@calTime
deftestTime():sum=0for i inrange(100000000):sum+=1if __name__ =="__main__":
testTime()
python中计算程序运行时间使用装饰器import timedef calTime(func): def fun(): start = time.time() func() end = time.time() print("程序运行时间为{}".format(end-start)) return fun@calTimedef testTime(): sum = 0 for i in range(1