MCPcopy Create free account
hub / github.com/daniel2005d/mapXplore / Stopwatch

Class Stopwatch

lib/stopwatch.py:4–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2
3
4class Stopwatch:
5 def __init__(self):
6 self.start_time = None
7 self.end_time = None
8
9 def start(self):
10 self.start_time = time.time()
11
12 def stop(self):
13 self.end_time = time.time()
14
15 def elapsed_time(self):
16 if self.start_time is None:
17 return 0
18 elif self.end_time is None:
19 return time.time() - self.start_time
20 else:
21 return self.end_time - self.start_time
22
23 def __str__(self):
24 seconds = self.elapsed_time()
25 hours = int(seconds // 3600)
26 seconds %= 3600
27 minutes = int(seconds // 60)
28 seconds %= 60
29 milliseconds = int((seconds - int(seconds)) * 1000)
30 seconds = int(seconds)
31 return f"{hours:02}:{minutes:02}:{seconds:02}.{milliseconds:03}"

Callers 1

startMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected