Stop timing for the given label and return the elapsed time. Args: label: The label to stop timing for Returns: The elapsed time in seconds Raises: ValueError: If the timer for the given label is not running
(self, label: str)
| 83 | self._start_times[label] = time.perf_counter() |
| 84 | |
| 85 | def stop(self, label: str) -> float: |
| 86 | """Stop timing for the given label and return the elapsed time. |
| 87 | |
| 88 | Args: |
| 89 | label: The label to stop timing for |
| 90 | |
| 91 | Returns: |
| 92 | The elapsed time in seconds |
| 93 | |
| 94 | Raises: |
| 95 | ValueError: If the timer for the given label is not running |
| 96 | """ |
| 97 | if label not in self._start_times: |
| 98 | raise ValueError( |
| 99 | f"Timer '{label}' is not running. Running times: {self._start_times.keys()}" |
| 100 | ) |
| 101 | |
| 102 | elapsed = time.perf_counter() - self._start_times[label] |
| 103 | if label not in self._timers: |
| 104 | self._timers[label] = [] |
| 105 | self._timers[label].append(elapsed) |
| 106 | del self._start_times[label] |
| 107 | return elapsed |
| 108 | |
| 109 | @contextmanager |
| 110 | def time(self, label: str) -> Generator[None, None, None]: |
no outgoing calls
no test coverage detected