From 87caf2e4da3bb46af6a9336211fcd9a333d38a96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:01:34 +0300 Subject: [PATCH 01/11] Add functions --- Week04/functions_gokhan_koray_bulbul.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week04/functions_gokhan_koray_bulbul.py diff --git a/Week04/functions_gokhan_koray_bulbul.py b/Week04/functions_gokhan_koray_bulbul.py new file mode 100644 index 00000000..60b2a55b --- /dev/null +++ b/Week04/functions_gokhan_koray_bulbul.py @@ -0,0 +1,25 @@ +custom_power = lambda x = 0, /, e = 1: x ** e + +def custom_equation(x: float = 0, y: float = 0, /, a: float = 1, b: float = 1, *, c: float = 1) -> float: + """This function returns a float value of the equation (x ** a + y ** b) / c + + :param x: The first term of the equation. Default is 0. + :param y: The second term of the equation. Default is 0. + :param a: The exponent for the first term of the equation. Default is 1. + :param b: The exponent for the second term of the equation. Default is 1. + :param c: The divisor for the entire equation. Default is 1. + :return: The result of the equation (x ** a + y ** b) / c as a float. + """ + return (custom_power(x, e = a) + custom_power(y, e = b)) / c + +def fn_w_counter(): + if not hasattr(fn_w_counter, "counter"): + fn_w_counter.counter = 0 + fn_w_counter.callers = {} + fn_w_counter.counter += 1 + caller_name = __name__ + if caller_name in fn_w_counter.callers: + fn_w_counter.callers[caller_name] += 1 + else: + fn_w_counter.callers[caller_name] = 1 + return fn_w_counter.counter, fn_w_counter.callers From afbd74bf293c4cdd74d5b9e68083811e37b5af57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:12:42 +0300 Subject: [PATCH 02/11] Add decorator This decorator tracks the execution time and memory usage of functions, storing statistics as attributes on the wrapper. --- Week04/decorators_gokhan_koray_bulbul.py | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Week04/decorators_gokhan_koray_bulbul.py diff --git a/Week04/decorators_gokhan_koray_bulbul.py b/Week04/decorators_gokhan_koray_bulbul.py new file mode 100644 index 00000000..6a6d18ce --- /dev/null +++ b/Week04/decorators_gokhan_koray_bulbul.py @@ -0,0 +1,38 @@ +import time +import tracemalloc + +def performance_tracker(func): + """ + A decorator that measures execution time and memory usage. + Statistics are stored as attributes on the wrapper function. + """ + def wrapper(*args, **kwargs): + # 1. Increment the call counter + wrapper.counter += 1 + + # 2. Start memory tracking + tracemalloc.start() + + # 3. Start timer + start_time = time.perf_counter() + + # Execute the original function + result = func(*args, **kwargs) + + # 4. Stop timer and calculate duration + end_time = time.perf_counter() + wrapper.total_time += (end_time - start_time) + + # 5. Get memory stats (current, peak) and stop tracking + _, peak = tracemalloc.get_traced_memory() + wrapper.total_mem += peak + tracemalloc.stop() + + return result + + # Initialize the required attributes on the wrapper function + wrapper.counter = 0 + wrapper.total_time = 0.0 + wrapper.total_mem = 0 + + return wrapper From e1e6ef6d746beff170d209668f01786e09452478 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:14:33 +0300 Subject: [PATCH 03/11] Update decorators_gokhan_koray_bulbul.py --- Week04/decorators_gokhan_koray_bulbul.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/decorators_gokhan_koray_bulbul.py b/Week04/decorators_gokhan_koray_bulbul.py index 6a6d18ce..70543f18 100644 --- a/Week04/decorators_gokhan_koray_bulbul.py +++ b/Week04/decorators_gokhan_koray_bulbul.py @@ -1,7 +1,7 @@ import time import tracemalloc -def performance_tracker(func): +def performance(func): """ A decorator that measures execution time and memory usage. Statistics are stored as attributes on the wrapper function. From 6eaa2253352ec0dd65f12c2806930c0afe9f47ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:22:32 +0300 Subject: [PATCH 04/11] Add awaitme function --- Week05/awaitme_gokhan_koray_bulbul.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Week05/awaitme_gokhan_koray_bulbul.py diff --git a/Week05/awaitme_gokhan_koray_bulbul.py b/Week05/awaitme_gokhan_koray_bulbul.py new file mode 100644 index 00000000..308cb323 --- /dev/null +++ b/Week05/awaitme_gokhan_koray_bulbul.py @@ -0,0 +1,10 @@ +import asyncio + +def awaitme(givenFunction): + if asyncio.iscoroutinefunction(givenFunction): + return givenFunction + + async def wrapper(*args, **kwargs): + return givenFunction(*args, **kwargs) + + return wrapper From 3a4edef4a21b28ee53180c8715fc63abca970274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:29:51 +0300 Subject: [PATCH 05/11] Update functions_gokhan_koray_bulbul.py --- Week04/functions_gokhan_koray_bulbul.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_gokhan_koray_bulbul.py b/Week04/functions_gokhan_koray_bulbul.py index 60b2a55b..5ba5661e 100644 --- a/Week04/functions_gokhan_koray_bulbul.py +++ b/Week04/functions_gokhan_koray_bulbul.py @@ -12,7 +12,7 @@ def custom_equation(x: float = 0, y: float = 0, /, a: float = 1, b: float = 1, * """ return (custom_power(x, e = a) + custom_power(y, e = b)) / c -def fn_w_counter(): +def fn_w_counter(): -> (int, dict[str, int]) if not hasattr(fn_w_counter, "counter"): fn_w_counter.counter = 0 fn_w_counter.callers = {} From a9a687d12702f2dc179b5099a095e130b9d2d790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:31:14 +0300 Subject: [PATCH 06/11] Update functions_gokhan_koray_bulbul.py --- Week04/functions_gokhan_koray_bulbul.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_gokhan_koray_bulbul.py b/Week04/functions_gokhan_koray_bulbul.py index 5ba5661e..35d8c5cc 100644 --- a/Week04/functions_gokhan_koray_bulbul.py +++ b/Week04/functions_gokhan_koray_bulbul.py @@ -12,7 +12,7 @@ def custom_equation(x: float = 0, y: float = 0, /, a: float = 1, b: float = 1, * """ return (custom_power(x, e = a) + custom_power(y, e = b)) / c -def fn_w_counter(): -> (int, dict[str, int]) +def fn_w_counter() -> (int, dict[str, int]): if not hasattr(fn_w_counter, "counter"): fn_w_counter.counter = 0 fn_w_counter.callers = {} From 798694fc87e7d9c3752b2a591010ea002c5fa9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 00:37:24 +0300 Subject: [PATCH 07/11] Update functions_gokhan_koray_bulbul.py --- Week04/functions_gokhan_koray_bulbul.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week04/functions_gokhan_koray_bulbul.py b/Week04/functions_gokhan_koray_bulbul.py index 35d8c5cc..fba56a3b 100644 --- a/Week04/functions_gokhan_koray_bulbul.py +++ b/Week04/functions_gokhan_koray_bulbul.py @@ -1,6 +1,6 @@ custom_power = lambda x = 0, /, e = 1: x ** e -def custom_equation(x: float = 0, y: float = 0, /, a: float = 1, b: float = 1, *, c: float = 1) -> float: +def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int = 1) -> float: """This function returns a float value of the equation (x ** a + y ** b) / c :param x: The first term of the equation. Default is 0. From ca1828c35bae0522de7f074438302ff12aa5773b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 01:04:10 +0300 Subject: [PATCH 08/11] Update decorators_gokhan_koray_bulbul.py --- Week04/decorators_gokhan_koray_bulbul.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Week04/decorators_gokhan_koray_bulbul.py b/Week04/decorators_gokhan_koray_bulbul.py index 70543f18..5fd984a7 100644 --- a/Week04/decorators_gokhan_koray_bulbul.py +++ b/Week04/decorators_gokhan_koray_bulbul.py @@ -6,9 +6,14 @@ def performance(func): A decorator that measures execution time and memory usage. Statistics are stored as attributes on the wrapper function. """ - def wrapper(*args, **kwargs): + # Initialize the required attributes on the wrapper function + _performance.counter = 0 + _performance.total_time = 0.0 + _performance.total_mem = 0 + + def _performance(*args, **kwargs): # 1. Increment the call counter - wrapper.counter += 1 + _performance.counter += 1 # 2. Start memory tracking tracemalloc.start() @@ -21,18 +26,11 @@ def wrapper(*args, **kwargs): # 4. Stop timer and calculate duration end_time = time.perf_counter() - wrapper.total_time += (end_time - start_time) + _performance.total_time += (end_time - start_time) # 5. Get memory stats (current, peak) and stop tracking _, peak = tracemalloc.get_traced_memory() - wrapper.total_mem += peak + _performance.total_mem += peak tracemalloc.stop() - - return result - - # Initialize the required attributes on the wrapper function - wrapper.counter = 0 - wrapper.total_time = 0.0 - wrapper.total_mem = 0 - return wrapper + return _performance From f3ff7a65ce3115c05b46bb138a2613dbf2170f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 01:09:22 +0300 Subject: [PATCH 09/11] Update decorators_gokhan_koray_bulbul.py --- Week04/decorators_gokhan_koray_bulbul.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Week04/decorators_gokhan_koray_bulbul.py b/Week04/decorators_gokhan_koray_bulbul.py index 5fd984a7..f36d7d4e 100644 --- a/Week04/decorators_gokhan_koray_bulbul.py +++ b/Week04/decorators_gokhan_koray_bulbul.py @@ -6,12 +6,14 @@ def performance(func): A decorator that measures execution time and memory usage. Statistics are stored as attributes on the wrapper function. """ - # Initialize the required attributes on the wrapper function - _performance.counter = 0 - _performance.total_time = 0.0 - _performance.total_mem = 0 def _performance(*args, **kwargs): + + # Initialize the required attributes on the wrapper function + _performance.counter = 0 + _performance.total_time = 0.0 + _performance.total_mem = 0 + # 1. Increment the call counter _performance.counter += 1 From cf42410f3155dd866f38dfa978106ded823077a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 01:13:20 +0300 Subject: [PATCH 10/11] Update decorators_gokhan_koray_bulbul.py --- Week04/decorators_gokhan_koray_bulbul.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Week04/decorators_gokhan_koray_bulbul.py b/Week04/decorators_gokhan_koray_bulbul.py index f36d7d4e..8d069b1d 100644 --- a/Week04/decorators_gokhan_koray_bulbul.py +++ b/Week04/decorators_gokhan_koray_bulbul.py @@ -7,15 +7,15 @@ def performance(func): Statistics are stored as attributes on the wrapper function. """ - def _performance(*args, **kwargs): + # Initialize the required attributes on the wrapper function + performance.counter = 0 + performance.total_time = 0.0 + performance.total_mem = 0 - # Initialize the required attributes on the wrapper function - _performance.counter = 0 - _performance.total_time = 0.0 - _performance.total_mem = 0 + def _performance(*args, **kwargs): # 1. Increment the call counter - _performance.counter += 1 + performance.counter += 1 # 2. Start memory tracking tracemalloc.start() @@ -28,11 +28,11 @@ def _performance(*args, **kwargs): # 4. Stop timer and calculate duration end_time = time.perf_counter() - _performance.total_time += (end_time - start_time) + performance.total_time += (end_time - start_time) # 5. Get memory stats (current, peak) and stop tracking _, peak = tracemalloc.get_traced_memory() - _performance.total_mem += peak + performance.total_mem += peak tracemalloc.stop() return _performance From ded13a8a1a4a3f1f94b5c64b9ba78d9a59cde4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khan=20Koray=20B=C3=BClb=C3=BCl?= <240315006@ogr.cbu.edu.tr> Date: Wed, 8 Apr 2026 14:14:14 +0300 Subject: [PATCH 11/11] Create timer_gokhan_koray_bulbul.py --- Week06/timer_gokhan_koray_bulbul.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Week06/timer_gokhan_koray_bulbul.py diff --git a/Week06/timer_gokhan_koray_bulbul.py b/Week06/timer_gokhan_koray_bulbul.py new file mode 100644 index 00000000..a575b932 --- /dev/null +++ b/Week06/timer_gokhan_koray_bulbul.py @@ -0,0 +1,14 @@ +import time + +class Timer: + def __init__(self): + self.start_time = 0.0 + self.end_time = 0.0 + + def __enter__(self): + self.start_time = time.time() + return self + + def __exit__(self, a, b, c): + self.end_time = time.time() + return True \ No newline at end of file