You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dops/task2.py

31 lines
751 B

import time
'''Вспомогательная функция для тестов'''
def Sum(m):
s = 0
for i in range(0, m):
s += i
return s
'''Менеджер контекста'''
class Timer():
def __init__(self):
self.start = None
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
print(time.time() - self.start)
'''Проверка Менеджера контекста'''
with Timer():
with Timer():
print(Sum(1000))
with Timer():
print('sum: ' + str(Sum(10000000)), end=', time: ')
with Timer():
time.sleep(1.4)