parent
ca43853f1a
commit
feb92564b2
@ -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) |
Loading…
Reference in new issue