EasyMocap/code/mytools/utils.py

22 lines
554 B
Python
Raw Normal View History

2021-01-24 22:33:08 +08:00
'''
@ Date: 2021-01-15 11:12:00
@ Author: Qing Shuai
@ LastEditors: Qing Shuai
2021-01-29 21:30:29 +08:00
@ LastEditTime: 2021-01-25 21:36:42
2021-01-24 22:33:08 +08:00
@ FilePath: /EasyMocap/code/mytools/utils.py
'''
import time
class Timer:
def __init__(self, name, silent=False):
self.name = name
self.silent = silent
def __enter__(self):
self.start = time.time()
def __exit__(self, exc_type, exc_value, exc_tb):
end = time.time()
if not self.silent:
2021-01-29 21:30:29 +08:00
print('-> [{:20s}]: {:5.1f}ms'.format(self.name, (end-self.start)*1000))