| 43 | |
| 44 | |
| 45 | class Timings: |
| 46 | def __init__(self): |
| 47 | self.timings = {} |
| 48 | |
| 49 | def add(self, name, duration): |
| 50 | assert name not in self.timings |
| 51 | self.timings[name] = duration |
| 52 | |
| 53 | def duration(self) -> float: |
| 54 | return self.timings["duration"] |
| 55 | |
| 56 | def to_dict(self): |
| 57 | return dict(self.timings) |
| 58 | |
| 59 | def __repr__(self): |
| 60 | return repr(self.timings) |
| 61 | |
| 62 | @contextlib.contextmanager |
| 63 | def time(self, name="duration"): |
| 64 | start = time.time() |
| 65 | yield |
| 66 | duration = time.time() - start |
| 67 | self.add(name, duration) |
no outgoing calls
no test coverage detected