From 5475d9cd7e7e7165f0e777eae674cfed858a13c1 Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Mon, 10 Nov 2025 00:58:42 +0300 Subject: [PATCH 1/3] add:functions_ardadeniz_kinikli --- Week04/functions_ardadeniz_kinikli.py | 38 +++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Week04/functions_ardadeniz_kinikli.py diff --git a/Week04/functions_ardadeniz_kinikli.py b/Week04/functions_ardadeniz_kinikli.py new file mode 100644 index 00000000..f61ca764 --- /dev/null +++ b/Week04/functions_ardadeniz_kinikli.py @@ -0,0 +1,38 @@ +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 computes the result of the expression (x**a + y**b) / c. + + :param x: The base for the first exponentiation. Positional-only. + :type x: int + :param y: The base for the second exponentiation. Positional-only. + :type y: int + :param a: The exponent for x. Positional-or-keyword. + :type a: int + :param b: The exponent for y. Positional-or-keyword. + :type b: int + :param c: The divisor. Keyword-only. Defaults to 1. + :type c: int + :returns: The result of the calculation. + :rtype: float + + """ + return (custom_power(x,a) + custom_power(y,b))/c + +def fn_w_counter() -> tuple[int, dict[str, int]]: + if not hasattr(fn_w_counter, "count"): + setattr(fn_w_counter, "count", 0) + fn_w_counter.count += 1 + temp_dict = {} + temp_dict[(str)(__name__)] = fn_w_counter.count + temp_tuple = (fn_w_counter.count, temp_dict) + return temp_tuple + +if __name__ == "__main__": + print(custom_power(2,3)) + print(custom_power(2,e=3)) + print(custom_equation(2, 2, a=3, b=3,c=1)) + for i in range(5): + fn_w_counter() + print(fn_w_counter()) \ No newline at end of file From 00564f497ed2eafa497882e0a99d09e7a23a4a88 Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Fri, 14 Nov 2025 20:07:56 +0300 Subject: [PATCH 2/3] add: decorators_ardadeniz_kinikli --- Week04/decorators_ardadeniz_kinikli.py | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Week04/decorators_ardadeniz_kinikli.py diff --git a/Week04/decorators_ardadeniz_kinikli.py b/Week04/decorators_ardadeniz_kinikli.py new file mode 100644 index 00000000..eda1c695 --- /dev/null +++ b/Week04/decorators_ardadeniz_kinikli.py @@ -0,0 +1,37 @@ +import time +import sys +def performance(func): + if not hasattr(performance,"counter"): + setattr(performance,"counter",0) + + if not hasattr(performance,"total_time"): + setattr(performance,"total_time",0) + + if not hasattr(performance,"total_mem"): + setattr(performance,"total_mem",0) + + def _d1(): + memory_used = sys.getsizeof(func) + start_time = time.time_ns() + func() + performance.counter += 1 + end_time = time.time_ns() + elapsed = 0 + elapsed = end_time - start_time + performance.total_time += (int)(elapsed/1e9) + performance.total_mem += memory_used + return (performance.counter, performance.total_time, performance.total_mem) + + return _d1 + + +if __name__ == "__main__": + @performance + def function_to_test(): + time.sleep(1) + + def function(): + for i in range(1): + function_to_test() + function() + print(function_to_test()) From f812c6e7e7017f72ed1ee9ccd727928fb2373b99 Mon Sep 17 00:00:00 2001 From: ArdaDenizKinikli Date: Mon, 30 Mar 2026 16:43:29 +0300 Subject: [PATCH 3/3] Decorator file changed --- Week04/decorators_ardadeniz_kinikli.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Week04/decorators_ardadeniz_kinikli.py b/Week04/decorators_ardadeniz_kinikli.py index eda1c695..fed62cdd 100644 --- a/Week04/decorators_ardadeniz_kinikli.py +++ b/Week04/decorators_ardadeniz_kinikli.py @@ -11,17 +11,16 @@ def performance(func): setattr(performance,"total_mem",0) def _d1(): - memory_used = sys.getsizeof(func) - start_time = time.time_ns() - func() - performance.counter += 1 - end_time = time.time_ns() - elapsed = 0 + tracemalloc.start() + start_time = time.perf_counter() + result = func(*args,**kwargs) + end_time = time.perf_counter() elapsed = end_time - start_time - performance.total_time += (int)(elapsed/1e9) - performance.total_mem += memory_used - return (performance.counter, performance.total_time, performance.total_mem) - + current_mem, peak_mem = tracemalloc.get_traced_memory() + performance.counter += 1 + performance.total_time += elapsed + performance.total_mem += peak_mem + return result return _d1