From ef7115ab52b80bb259c723bf285fd0522397129f Mon Sep 17 00:00:00 2001 From: Sidney Zhang Date: Tue, 15 Sep 2026 16:50:29 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E7=A7=BB=E9=99=A4=20euler=5F56=20?= =?UTF-8?q?=E4=B8=AD=E6=9C=AA=E4=BD=BF=E7=94=A8=E7=9A=84=20MAX=5FEMAX=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=B9=B6=E6=B7=BB=E5=8A=A0=20euler=5F57=20?= =?UTF-8?q?=E5=9F=BA=E5=87=86=E6=B5=8B=E8=AF=95=E8=A3=85=E9=A5=B0=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solutions/0056.PowerfulDigitSum/euler_56.py | 1 - solutions/0057.SquareRoot/euler_57.py | 40 +++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 solutions/0057.SquareRoot/euler_57.py diff --git a/solutions/0056.PowerfulDigitSum/euler_56.py b/solutions/0056.PowerfulDigitSum/euler_56.py index ef30316..cacb080 100644 --- a/solutions/0056.PowerfulDigitSum/euler_56.py +++ b/solutions/0056.PowerfulDigitSum/euler_56.py @@ -7,7 +7,6 @@ Considering natural numbers of the form, a^b , where a,b < 100 , what is the max """ import time -from decimal import MAX_EMAX from functools import wraps from typing import Any, Callable, TypeVar diff --git a/solutions/0057.SquareRoot/euler_57.py b/solutions/0057.SquareRoot/euler_57.py new file mode 100644 index 0000000..52ff584 --- /dev/null +++ b/solutions/0057.SquareRoot/euler_57.py @@ -0,0 +1,40 @@ +''' + +''' +import time +from functools import wraps +from typing import Any, Callable, TypeVar + +F = TypeVar("F", bound=Callable[..., Any]) + + +def benchmark(repeat: int = 1) -> Callable[[F], F]: + if repeat < 1: + raise ValueError("repeat must >= 1") + + def decorator(func: F) -> F: + @wraps(func) + def wrapper(*args: Any, **kwargs: Any) -> Any: + total = 0.0 + result = None + + for _ in range(repeat): + start = time.perf_counter() + result = func(*args, **kwargs) + end = time.perf_counter() + total += end - start + + wrapper.avg_time = total / repeat # type: ignore[attr-defined] + wrapper.total_time = total # type: ignore[attr-defined] + + print( + f"[Benchmark] {func.__name__} | repeated {repeat} times | " + f"average: {wrapper.avg_time:.6f}s | total: {wrapper.total_time:.6f}s" # type: ignore[attr-defined] + ) + return result + + wrapper.avg_time = 0.0 # type: ignore[attr-defined] + wrapper.total_time = 0.0 # type: ignore[attr-defined] + return wrapper # type: ignore[return-value] + + return decorator \ No newline at end of file