|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import time as t
class MyTimer():
def __init__(self,func,count = 1):
self.temp = 0
self.prompt = '总共运行了0秒'
self.cou = count
self.func = func
def __str__(self):
return self.prompt
__repr__ = __str__
def timing(self):
while self.cou:
self.bagin = t.perf_counter()
self.func()
self.end = t.perf_counter()
self.temp += self.end - self.bagin
self.cou -= 1
self.prompt = '总共运行了%0.2f秒'%self.temp
def __add__(self,other):
self.atemp = self.temp + other.temp
self.aprompt = '总共运行了%0.2f秒'%self.atemp
return self.aprompt
这是我写的代码,按照小甲鱼方法的运行
>>> ================================ RESTART ================================
>>>
>>> def test():
text = "I love FishC.com!"
char = 'o'
if char in text:
pass
>>> t1 = MyTimer(test)
>>> t1.timing()
>>> t1
总共运行了 0.00秒
请问为什么运行结果是0秒? |
|