From 0f65d2aa98bfadae7b2d53d2c64b156e30acd245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C5=9Fir=20Se=C3=A7ilmi=C5=9F?= <136277855+Apexq@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:08:30 +0300 Subject: [PATCH 1/3] Add performance decorator for function metrics Implement a performance decorator to track execution time and memory usage. --- Week04/decorators_besir_secilmis.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Week04/decorators_besir_secilmis.py diff --git a/Week04/decorators_besir_secilmis.py b/Week04/decorators_besir_secilmis.py new file mode 100644 index 00000000..3daa62a1 --- /dev/null +++ b/Week04/decorators_besir_secilmis.py @@ -0,0 +1,20 @@ +import tracemalloc +import time + +def performance(func): + performance.counter = 0 + performance.total_time = 0.0 + performance.total_mem = 0.0 + + def wrapper(*args, **kwargs): + tracemalloc.start() + start_time = time.time() + result = func(*args, **kwargs) + end_time = time.time() + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + performance.counter += 1 + performance.total_time += (end_time - start_time) + performance.total_mem += peak + return result + return wrapper From f0288b93358211859e45b547f542cdb4850ec859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C5=9Fir=20Se=C3=A7ilmi=C5=9F?= <136277855+Apexq@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:09:58 +0300 Subject: [PATCH 2/3] Add custom equation and call counter functions This file contains functions for custom power calculations and a counter for function calls. --- Week04/functions_besir_secilmis.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Week04/functions_besir_secilmis.py diff --git a/Week04/functions_besir_secilmis.py b/Week04/functions_besir_secilmis.py new file mode 100644 index 00000000..4769baa7 --- /dev/null +++ b/Week04/functions_besir_secilmis.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 calculates a custom equation with the given five integers. + + :param x: First base value + :param y: Second base value + :param a: Exponent of variable x + :param b: Exponent of variable y + :param c: Divisor value + :return: The float result of the operation + """ + + return (x**a + y**b) / c + +def fn_w_counter() -> (int, dict[str, int]): + if not hasattr(fn_w_counter,'call_counter'): + fn_w_counter.call_counter = 0 + fn_w_counter.caller_dict = {} + caller = __name__ + fn_w_counter.call_counter += 1 + if caller in fn_w_counter.caller_dict: + fn_w_counter.caller_dict[caller] += 1 + else: + fn_w_counter.caller_dict[caller] = 1 + return fn_w_counter.call_counter,fn_w_counter.caller_dict From 396adaa9317cd8c583a597d04a9bb50076c941d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C5=9Fir=20Se=C3=A7ilmi=C5=9F?= <136277855+Apexq@users.noreply.github.com> Date: Thu, 2 Apr 2026 13:10:46 +0300 Subject: [PATCH 3/3] Add awaitme decorator for asynchronous functions --- Week05/awaitme_besir_secilmis.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Week05/awaitme_besir_secilmis.py diff --git a/Week05/awaitme_besir_secilmis.py b/Week05/awaitme_besir_secilmis.py new file mode 100644 index 00000000..27e30737 --- /dev/null +++ b/Week05/awaitme_besir_secilmis.py @@ -0,0 +1,5 @@ +def awaitme(func): + async def wrapper(*args,**kwargs): + result = func(*args,**kwargs) + return result + return wrapper