-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtiming.py
More file actions
36 lines (25 loc) · 707 Bytes
/
timing.py
File metadata and controls
36 lines (25 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import time
class _TimingBase:
timing = {}
@classmethod
def get(cls):
return cls.timing
@classmethod
def reset(cls):
cls.timing = {}
def __init__(self, name):
self._name = name
def __enter__(self):
self._t0 = time.time()
def __exit__(self, *exc_args):
self.__class__.timing[self._name] = time.time() - self._t0
registry = {}
def makeOrGetTimingClass(name: str):
if name not in registry:
registry[name] = type(f'Timing_{name}', (_TimingBase,), {'timing': {}})
return registry[name]
class Global(_TimingBase):
"""
A global timing class that can be used to track timing anywhere
"""
timing = {}