Move timer to a separate module

This commit is contained in:
Michel Breyer
2021-08-05 13:45:22 +02:00
parent 5d17498084
commit 6fa4007727
3 changed files with 26 additions and 26 deletions

22
active_grasp/timer.py Normal file
View File

@@ -0,0 +1,22 @@
import time
class Timer:
timers = dict()
def __init__(self, name):
self.name = name
def __enter__(self):
self.start()
return self
def __exit__(self, *exc_info):
self.stop()
def start(self):
self.tic = time.perf_counter()
def stop(self):
elapsed_time = time.perf_counter() - self.tic
self.timers[self.name] = elapsed_time