builtup4/timesample.py

21 lines
409 B
Python

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()
def __exit__(self, exc_type, exc_val, exc_tb):
TimeSample.level -= 1
print(' ' * 4 * self.level, end='')
print(*self.args, time.time() - self.__t)
print()