没有使用class
a = time.time()
for i in range(1, 1000000):
i+=i
print(i)
b = time.time()
c= b-a
print(c)
stop_watch 类
class stop_watch:
def __init__(self, start_time, end_time):
self.__start_time = start_time
self.__end_time = end_time
def set_start(self, start_time):
self.__start_time = start_time
def set_end(self, end_time):
self.__end_time = end_time
def get_start(self):
return self.__start_time
def get_end(self):
return self.__end_time
def get_elapsed_time(self):
return stop_watch.get_end(self) - stop_watch.get_start(self)
方法
def main():
a =time.time()
for i in range(1, 1000000):
i+=i
print(i)
b = time.time()
c1 = exCode07.stop_watch(a,b)
print("total times is",c1.get_elapsed_time())
main()
运行结果