MCPcopy Index your code
hub / github.com/bpython/bpython / RuntimeTimer

Class RuntimeTimer

bpython/repl.py:76–100  ·  view source on GitHub ↗

Calculate running time

Source from the content-addressed store, hash-verified

74
75
76class 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
103class Interpreter(code.InteractiveInterpreter):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected