[+] Timer

This commit is contained in:
Azalea (on HyDEV-Daisy)
2022-04-09 00:16:45 -04:00
parent 26b2334490
commit 6466cb8311
2 changed files with 23 additions and 2 deletions
Regular → Executable
+2 -1
View File
@@ -5,7 +5,8 @@ set -e
VERSION=$(python3 -c 'import hypy_utils; print(hypy_utils.__version__)') VERSION=$(python3 -c 'import hypy_utils; print(hypy_utils.__version__)')
echo "$VERSION" echo "$VERSION"
rm dist/* mkdir -p dist
rm -rf dist/*
# Build # Build
python3 setup.py sdist bdist_wheel python3 setup.py sdist bdist_wheel
+21 -1
View File
@@ -1,8 +1,9 @@
__version__ = "1.0.2" __version__ = "1.0.3"
import dataclasses import dataclasses
import hashlib import hashlib
import json import json
import time
from datetime import datetime, date from datetime import datetime, date
from pathlib import Path from pathlib import Path
from typing import Union from typing import Union
@@ -173,3 +174,22 @@ def md5(file: Union[str, Path]) -> str:
for chunk in iter(lambda: f.read(4096), b""): for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk) hash_md5.update(chunk)
return hash_md5.hexdigest() return hash_md5.hexdigest()
class Timer:
start: int
def __init__(self):
self.reset()
def elapsed(self, reset: bool = True) -> float:
t = (time.time_ns() - self.start) / 1000000
if reset:
self.reset()
return t
def log(self, *args):
print(f'{self.elapsed():.0f}ms', *args)
def reset(self):
self.start = time.time_ns()