From feb92564b29b578813d26151e3185d415dc183e0 Mon Sep 17 00:00:00 2001 From: MexTest Date: Fri, 13 Jan 2023 07:50:03 +0000 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB(=D0=B0)=20=D1=84=D0=B0=D0=B9=D0=BB=D1=8B=20=D0=B2=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task2.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 task2.py diff --git a/task2.py b/task2.py new file mode 100644 index 0000000..a2c4716 --- /dev/null +++ b/task2.py @@ -0,0 +1,31 @@ +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)