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