Skip to content
Merged
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
25 changes: 25 additions & 0 deletions Week04/decorators_ardadeniz_kinikli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import time
import tracemalloc
def performance(func):
if not hasattr(performance,"counter"):
setattr(performance,"counter",0)

if not hasattr(performance,"total_time"):
setattr(performance,"total_time",0)

if not hasattr(performance,"total_mem"):
setattr(performance,"total_mem",0)

def _d1(*args,**kwargs):
tracemalloc.start()
start_time = time.perf_counter()
result = func(*args,**kwargs)
end_time = time.perf_counter()
elapsed = end_time - start_time
current_mem, peak_mem = tracemalloc.get_traced_memory()
performance.counter += 1
performance.total_time += elapsed
performance.total_mem += peak_mem
return result
return _d1

31 changes: 31 additions & 0 deletions Week04/functions_ardadeniz_kinikli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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:
"""
This function computes the result of the expression (x**a + y**b) / c.

:param x: The base for the first exponentiation. Positional-only.
:type x: int
:param y: The base for the second exponentiation. Positional-only.
:type y: int
:param a: The exponent for x. Positional-or-keyword.
:type a: int
:param b: The exponent for y. Positional-or-keyword.
:type b: int
:param c: The divisor. Keyword-only. Defaults to 1.
:type c: int
:returns: The result of the calculation.
:rtype: float

"""
return (custom_power(x,a) + custom_power(y,b))/c

def fn_w_counter() -> (int, dict[str, int]):
if not hasattr(fn_w_counter, "count"):
setattr(fn_w_counter, "count", 0)
setattr(fn_w_counter,"dictionary",{})
fn_w_counter.count += 1
fn_w_counter.dictionary[(str)(__name__)] = fn_w_counter.count
return fn_w_counter.count,fn_w_counter.dictionary


Loading