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
33 changes: 33 additions & 0 deletions Week04/decorators_sedat_celik.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import time
import tracemalloc
import functools


def performance(func):

@functools.wraps(func)
def wrapper(*args, **kwargs):

tracemalloc.start()
start_time = time.perf_counter()
start_mem = tracemalloc.get_traced_memory()[0]

try:
return func(*args, **kwargs)

finally:
end_time = time.perf_counter()
peak_mem = tracemalloc.get_traced_memory()[1]

performance.counter += 1
performance.total_time += end_time - start_time
performance.total_mem += max(peak_mem - start_mem, 0)

tracemalloc.stop()

return wrapper


performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0
36 changes: 36 additions & 0 deletions Week04/functions_sedat_celik.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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 and returns the custom equation

:param x: first positional-only base value, default is 0
:type x: int
:param y: second positional-only value, default is 0
:type y: int
:param a: exponent of x, default is 1
:type a: int
:param b: exponent of y, default is 1
:type b: int
:param c: keyword-only divisor value, default is 1
:type c: int
:return: the calculated result of the equation (x**a + y**b) / c
:rtype: float
"""

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


def fn_w_counter() -> (int, dict[str, int]):
if not hasattr(fn_w_counter, "total_calls"):
fn_w_counter.total_calls = 0
fn_w_counter.caller_counts = {}

caller = __name__

fn_w_counter.total_calls += 1
fn_w_counter.caller_counts[caller] = (
fn_w_counter.caller_counts.get(caller, 0) + 1
)

return fn_w_counter.total_calls, dict(fn_w_counter.caller_counts)
Loading