Spaces:
Sleeping
Sleeping
# -*- coding: utf-8 -*- | |
"""ใฆใผใใฃใชใใฃ""" | |
from dataclasses import dataclass | |
import time | |
def get_package_version() -> str: | |
""" | |
ใใผใธใงใณๆ ๅ ฑ | |
""" | |
return '0.0.8' | |
class Stopwatch: | |
""" | |
็ต้ๆ้ใ่จๆธฌใใใใใฎใฏใฉในใ | |
Example: | |
from src.utils import Stopwatch | |
watch = Stopwatch.start_new() | |
### ่จๆธฌใใๅฆ็ | |
print(f"{watch.elapsed:.3f}") | |
""" | |
_start_time: float = 0 | |
_elapsed: float = 0 | |
_is_running: bool = False | |
def elapsed(self) -> float: | |
""" | |
็ต้ๆ้ใๅๅพใใพใใ | |
""" | |
if self._is_running: | |
end_time = time.perf_counter() | |
self._elapsed = end_time - self._start_time | |
return self._elapsed | |
def is_running(self) -> bool: | |
""" | |
ๅฎ่กไธญใใฉใใใๅๅพใใพใใ | |
""" | |
return self._is_running | |
def start(self) -> None: | |
""" | |
่จๆธฌใ้ๅงใใพใใ | |
""" | |
self._start_time = time.perf_counter() | |
self._elapsed = 0 | |
self._is_running = True | |
def start_new(cls): | |
""" | |
ในใใใใฆใฉใใใ็ๆใ่จๆธฌใ้ๅงใใพใใ | |
""" | |
stopwatch = Stopwatch() | |
stopwatch.start() | |
return stopwatch | |
def stop(self) -> float: | |
""" | |
่จๆธฌใ็ตไบใใพใใ | |
""" | |
if self._is_running: | |
end_time = time.perf_counter() | |
self._elapsed = end_time - self._start_time | |
self._is_running = False | |
return self._elapsed | |