from time import sleep
from time import time
from contextlib import contextmanager


class cm_timer_1:
    def __enter__(self):
        self.start = time()

    def __exit__(self, exc_type, exc_val, exc_tb):
        print(time() - self.start)


@contextmanager
def cm_timer_2():
    start = time()
    yield
    print(time() - start)


if __name__ == '__main__':
    with cm_timer_1():
        sleep(5.5)

    with cm_timer_2():
        sleep(5.5)
