From 90c5be452c7193ff7f90a824eb6e3b56c8fba690 Mon Sep 17 00:00:00 2001 From: Helin Date: Tue, 23 Dec 2025 10:46:30 +0300 Subject: [PATCH] Implement performance tracking decorator This decorator tracks the performance of functions by measuring execution time and memory usage. --- Week04/decorators_helin_harman.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Week04/decorators_helin_harman.py diff --git a/Week04/decorators_helin_harman.py b/Week04/decorators_helin_harman.py new file mode 100644 index 00000000..38286739 --- /dev/null +++ b/Week04/decorators_helin_harman.py @@ -0,0 +1,31 @@ +import time +import tracemalloc +from functools import wraps + + +def performance(func): + @wraps(func) + def wrapper(*args, **kwargs): + performance.counter += 1 + + start_time = time.perf_counter() + tracemalloc.start() + + result = func(*args, **kwargs) + + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + end_time = time.perf_counter() + + performance.total_time += end_time - start_time + performance.total_mem += peak + + return result + + return wrapper + + +# decorator attribute'ları (TESTLER BUNU BEKLİYOR) +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0