diff --git a/Week04/decorators_mert_yuksel.py b/Week04/decorators_mert_yuksel.py new file mode 100644 index 00000000..4c2a6a03 --- /dev/null +++ b/Week04/decorators_mert_yuksel.py @@ -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 \ No newline at end of file diff --git a/Week04/functions_mert_yuksel.py b/Week04/functions_mert_yuksel.py new file mode 100644 index 00000000..2d0eb829 --- /dev/null +++ b/Week04/functions_mert_yuksel.py @@ -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} \ No newline at end of file diff --git a/Week05/awaitme_mert_yuksel.py b/Week05/awaitme_mert_yuksel.py new file mode 100644 index 00000000..a4774153 --- /dev/null +++ b/Week05/awaitme_mert_yuksel.py @@ -0,0 +1,7 @@ +def awaitme(func): + + async def _awaitme(*args, **kwargs): + result = func(*args, **kwargs) + return result + + return _awaitme \ No newline at end of file