From 4313db5f74451391c5ae4a1369647e36833c36cd Mon Sep 17 00:00:00 2001 From: ArdaOmer Date: Tue, 31 Mar 2026 20:12:42 +0300 Subject: [PATCH] Create: decorators_arda_omer.py and functions_arda_omer.py --- Week04/decorators_arda_omer.py | 28 ++++++++++++++++++++++++ Week04/functions_arda_omer.py | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 Week04/decorators_arda_omer.py create mode 100644 Week04/functions_arda_omer.py diff --git a/Week04/decorators_arda_omer.py b/Week04/decorators_arda_omer.py new file mode 100644 index 00000000..2e9083b9 --- /dev/null +++ b/Week04/decorators_arda_omer.py @@ -0,0 +1,28 @@ +import time +import tracemalloc +from functools import wraps + + +def performance(func): + @wraps(func) + def wrapper(*args, **kwargs): + tracemalloc.start() + start_time = time.perf_counter() + + result = func(*args, **kwargs) + + end_time = time.perf_counter() + current_mem, peak_mem = tracemalloc.get_traced_memory() + tracemalloc.stop() + + wrapper.counter += 1 + wrapper.total_time += end_time - start_time + wrapper.total_mem += peak_mem + + return result + + wrapper.counter = 0 + wrapper.total_time = 0.0 + wrapper.total_mem = 0 + + return wrapper \ No newline at end of file diff --git a/Week04/functions_arda_omer.py b/Week04/functions_arda_omer.py new file mode 100644 index 00000000..0df3e0f5 --- /dev/null +++ b/Week04/functions_arda_omer.py @@ -0,0 +1,40 @@ +import inspect + + +custom_power = lambda x=0, /, e=1: pow(x, e) + + +def custom_equation(x: int, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: + """ + Compute a custom equation result. + + :param x: First base value + :param y: Second base value + :param a: Power for x + :param b: Power for y + :param c: Divider + :return: Float result of the equation + """ + value_x = pow(x, a) + value_y = pow(y, b) + + combined = value_x + value_y + + if c == 0: + return 0.0 # safe fallback (division guard) + + return float(combined / c) + + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "_count"): + fn_w_counter._count = 0 + fn_w_counter._call_map = {} + + caller = inspect.stack()[1].frame.f_globals.get("__name__", "__main__") + + fn_w_counter._count += 1 + + fn_w_counter._call_map[caller] = fn_w_counter._call_map.get(caller, 0) + 1 + + return fn_w_counter._count, fn_w_counter._call_map \ No newline at end of file