From 6466cb83112a97818e12725515cc43248a592c0c Mon Sep 17 00:00:00 2001 From: "Azalea (on HyDEV-Daisy)" Date: Sat, 9 Apr 2022 00:16:45 -0400 Subject: [PATCH] [+] Timer --- deploy.sh | 3 ++- hypy_utils/__init__.py | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) mode change 100644 => 100755 deploy.sh diff --git a/deploy.sh b/deploy.sh old mode 100644 new mode 100755 index 041381b..387c41f --- a/deploy.sh +++ b/deploy.sh @@ -5,7 +5,8 @@ set -e VERSION=$(python3 -c 'import hypy_utils; print(hypy_utils.__version__)') echo "$VERSION" -rm dist/* +mkdir -p dist +rm -rf dist/* # Build python3 setup.py sdist bdist_wheel diff --git a/hypy_utils/__init__.py b/hypy_utils/__init__.py index 1100c7c..8076878 100644 --- a/hypy_utils/__init__.py +++ b/hypy_utils/__init__.py @@ -1,8 +1,9 @@ -__version__ = "1.0.2" +__version__ = "1.0.3" import dataclasses import hashlib import json +import time from datetime import datetime, date from pathlib import Path from typing import Union @@ -173,3 +174,22 @@ def md5(file: Union[str, Path]) -> str: for chunk in iter(lambda: f.read(4096), b""): hash_md5.update(chunk) 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()