Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Bugs fixed
  • Loading branch information
protagonist9 committed Jan 5, 2026
commit 0ececc5b67301e742582a940287b75509b747054
38 changes: 20 additions & 18 deletions Week04/decorators_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import time, tracemalloc
from functools import wraps
import time
import tracemalloc

def performance(func):
performance.c = performance.c + 1 if hasattr(performance, "c") else 1
performance.t = getattr(performance, "t", 0.0)
performance.m = getattr(performance, "m", 0)

@wraps(func)
def wrapper(*a, **k):
performance.c += 1
t0 = time.perf_counter()
def wrapper(*args, **kwargs):
tracemalloc.start()
r = func(*a, **k)
performance.t += time.perf_counter() - t0
performance.m += tracemalloc.get_traced_memory()[1]
t1 = time.perf_counter()

result = func(*args, **kwargs)

t2 = time.perf_counter()
curr, peak = tracemalloc.get_traced_memory()
tracemalloc.stop()
return r
return wrapper

wrapper.counter += 1
wrapper.total_time += t2 - t1
wrapper.total_mem += peak

return result

performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0
wrapper.counter = 0
wrapper.total_time = 0
wrapper.total_mem = 0

return wrapper
44 changes: 18 additions & 26 deletions Week04/functions_tarik_bozgan.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
# custom_power (lambda)
custom_power = lambda x=0, e=1: x ** e
custom_power = lambda x, /, e=1: x ** e


def custom_equation(
x: int = 0,
y: int = 0,
a: int = 1,
b: int = 1,
*,
c: int = 1
) -> float:
def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float:
"""
:param x: integer value
:param y: integer value
:param a: integer value
:param b: integer value
:param c: integer value
:return: result of equation
:param x:
:param y:
:param a:
:param b:
:param c:
:return:
"""
if not all(isinstance(v, int) for v in (x, y, a, b, c)):
raise TypeError("All parameters must be int")

if not isinstance(x, int): raise TypeError("x must be int")
if not isinstance(y, int): raise TypeError("y must be int")
if not isinstance(a, int): raise TypeError("a must be int")
if not isinstance(b, int): raise TypeError("b must be int")
if not isinstance(c, int): raise TypeError("c must be int")

return (x ** a + y ** b) / c


_call_count = 0

_count = 0
def fn_w_counter() -> (int, dict[str, int]):
global _call_count
_call_count += 1
return _call_count, {__name__: _call_count}
global _count
_count += 1
return _count, {__name__: _count}
Loading