12345678910111213141516171819202122232425262728293031323334 |
- import time
- def calculate():
- for i in range(10000):
- 2 ** 2123
- # Расчет время выполнения функций
- class Timer:
- def __enter__(self):
- self.start = time.time()
- self.end = 0.0
- return lambda: self.end - self.start
- def __exit__(self, *args):
- self.end = time.time()
- def main():
- with Timer() as my_timer:
- time.sleep(0.6)
- print(my_timer())
- with Timer() as my_timer2:
- time.sleep(1.5)
- print(my_timer2())
- with Timer() as my_timer3:
- calculate()
- print(my_timer3())
- if __name__ == '__main__':
- main()
|