#  Copyright (c) PARRRATE T&V 2021. All rights reserved.

import time

__all__ = ('TimeSample',)


class TimeSample:
    level = 0

    def __init__(self, *args):
        self.args = args

    def __enter__(self):
        TimeSample.level += 1
        self.__t = time.time()

    @classmethod
    def tabulate(cls):
        print(' ' * 4 * cls.level, end='')

    @classmethod
    def print(cls, *args):
        cls.tabulate()
        print(*args)

    def __exit__(self, exc_type, exc_val, exc_tb):
        TimeSample.level -= 1
        self.tabulate()
        print(*self.args, time.time() - self.__t)
        print()