SaliencyMapDemo / src /utils.py
umyuu
Release 0.0.5
f65b63f
raw
history blame
1.26 kB
# -*- 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
@property
def elapsed(self):
"""
็ตŒ้Žๆ™‚้–“
"""
return self._elapsed
def start(self) -> None:
"""
่จˆๆธฌใ‚’้–‹ๅง‹ใ—ใพใ™ใ€‚
"""
self._start_time = time.perf_counter()
self._elapsed = 0
@classmethod
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