Spaces:
No application file
No application file
import time | |
class TextColors: | |
HEADER = '\033[35m' | |
OKBLUE = '\033[34m' | |
OKGREEN = '\033[32m' | |
WARNING = '\033[33m' | |
FATAL = '\033[31m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
class Timer(): | |
def __init__(self, name='task', verbose=True): | |
self.name = name | |
self.verbose = verbose | |
def __enter__(self): | |
self.start = time.time() | |
return self | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
if self.verbose: | |
print('[Time] {} consumes {:.4f} s'.format( | |
self.name, | |
time.time() - self.start)) | |
return exc_type is None |