Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Week04/decorators_arda_omer.py
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions Week04/functions_arda_omer.py
Original file line number Diff line number Diff line change
@@ -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