Calculate running time
| 74 | |
| 75 | |
| 76 | class RuntimeTimer: |
| 77 | """Calculate running time""" |
| 78 | |
| 79 | def __init__(self) -> None: |
| 80 | self.reset_timer() |
| 81 | |
| 82 | def __enter__(self) -> None: |
| 83 | self.start = time.monotonic() |
| 84 | |
| 85 | def __exit__( |
| 86 | self, |
| 87 | exc_type: type[BaseException] | None, |
| 88 | exc_val: BaseException | None, |
| 89 | exc_tb: TracebackType | None, |
| 90 | ) -> Literal[False]: |
| 91 | self.last_command = time.monotonic() - self.start |
| 92 | self.running_time += self.last_command |
| 93 | return False |
| 94 | |
| 95 | def reset_timer(self) -> None: |
| 96 | self.running_time = 0.0 |
| 97 | self.last_command = 0.0 |
| 98 | |
| 99 | def estimate(self) -> float: |
| 100 | return self.running_time - self.last_command |
| 101 | |
| 102 | |
| 103 | class Interpreter(code.InteractiveInterpreter): |