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

def performance(func):
"""
A decorater function that measures the performance of the given function and also save some statistics
(The definition is from lecture notes.pdf)
"""
performance.counter = 0
performance.total_mem = 0.0
performance.total_time = 0.0


def _performance(*args, **kwargs):
tm.start()
start_time = time.time()

result = func(*args, **kwargs)

_, peak_mem = tm.get_traced_memory()
endtime = time.time()

tm.stop()

performance.total_time += endtime - start_time
performance.total_mem += peak_mem
performance.counter += 1

return result

return _performance
27 changes: 27 additions & 0 deletions Week04/functions_mert_yuksel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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 does something

:param x: positional only argument, defaults to 0
:type x: int
:param y: poisitonal only argument, defaults to 0
:type y: int
:param a: positional or keyword argument, defaults to 1
:type a: int
:param b: positional or keyword argument, defaults to 1
:type b: int
:param c: keyword only argument, defaults to 1
:type c: int
:return: the result of division by c the sum of x to the power of a and y to the power of b
:rtype : float
"""
return (x**a + y **b) / c

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

fn_w_counter.count += 1
return fn_w_counter.count, {__name__: fn_w_counter.count}
7 changes: 7 additions & 0 deletions Week05/awaitme_mert_yuksel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def awaitme(func):

async def _awaitme(*args, **kwargs):
result = func(*args, **kwargs)
return result

return _awaitme
Loading