ClickHouse/tests/ci/stopwatch.py

21 lines
496 B
Python
Raw Normal View History

2021-11-19 14:47:04 +00:00
#!/usr/bin/env python3
import datetime
class Stopwatch:
2021-11-19 14:47:04 +00:00
def __init__(self):
self.reset()
2021-11-19 14:47:04 +00:00
@property
2023-01-03 11:55:12 +00:00
def duration_seconds(self) -> float:
2021-11-19 14:47:04 +00:00
return (datetime.datetime.utcnow() - self.start_time).total_seconds()
@property
2023-01-03 11:55:12 +00:00
def start_time_str(self) -> str:
2021-11-19 15:24:39 +00:00
return self.start_time_str_value
def reset(self) -> None:
self.start_time = datetime.datetime.utcnow()
self.start_time_str_value = self.start_time.strftime("%Y-%m-%d %H:%M:%S")