From b0006c93935346f84935ec4a92e60dfd5171beb8 Mon Sep 17 00:00:00 2001 From: Hilmi <163791964+Spohey@users.noreply.github.com> Date: Wed, 18 Nov 2026 19:11:06 +0300 Subject: [PATCH] Add files via upload --- Week04/decorators_hilmi_aydin.py | 33 ++++++++++++++++++++++++++++++++ Week04/functions_hilmi_aydin.py | 25 ++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 Week04/decorators_hilmi_aydin.py create mode 100644 Week04/functions_hilmi_aydin.py diff --git a/Week04/decorators_hilmi_aydin.py b/Week04/decorators_hilmi_aydin.py new file mode 100644 index 00000000..8ff30eb7 --- /dev/null +++ b/Week04/decorators_hilmi_aydin.py @@ -0,0 +1,33 @@ +import time +import tracemalloc + + +def performance(func): + def wrapper(*args, **kwargs): + + tracemalloc.start() + start = time.perf_counter() + start_mem = tracemalloc.get_traced_memory()[0] + tracemalloc.reset_peak() + + try: + result = func(*args, **kwargs) + + finally: + end = time.perf_counter() + current, peak = tracemalloc.get_traced_memory() + + performance.counter += 1 + performance.total_time += end - start + performance.total_mem += peak - start_mem + + tracemalloc.stop() + + return result + + return wrapper + + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 \ No newline at end of file diff --git a/Week04/functions_hilmi_aydin.py b/Week04/functions_hilmi_aydin.py new file mode 100644 index 00000000..2356907b --- /dev/null +++ b/Week04/functions_hilmi_aydin.py @@ -0,0 +1,25 @@ +custom_power = lambda x=0, /, e=1: x ** e + + +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: + """ + Calculates the result of (x**a + y**b) / c. + + :param x: First base, positional-only (default 0) + :param y: Second base, positional-only (default 0) + :param a: Exponent of x (default 1) + :param b: Exponent of y (default 1) + :param c: Divisor, keyword-only (default 1) + :return: The result as a float + """ + return (x ** a + y ** b) / c + + +def fn_w_counter() -> (int, dict[str, int]): + """Counts the total number of calls and the number of calls per caller.""" + if not hasattr(fn_w_counter, "total"): + fn_w_counter.total = 0 + fn_w_counter.callers = {} + fn_w_counter.total += 1 + fn_w_counter.callers[__name__] = fn_w_counter.callers.get(__name__, 0) + 1 + return fn_w_counter.total, fn_w_counter.callers \ No newline at end of file