From 2f91fc1ad46a65ad62f1e060384a68d693dc68ce Mon Sep 17 00:00:00 2001 From: Burakhan7 <141933959+Burakhan7@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:02:50 +0300 Subject: [PATCH 1/2] Create decorators_burakhan_gultoplar.py --- Week04/decorators_burakhan_gultoplar.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week04/decorators_burakhan_gultoplar.py diff --git a/Week04/decorators_burakhan_gultoplar.py b/Week04/decorators_burakhan_gultoplar.py new file mode 100644 index 00000000..3c2815e8 --- /dev/null +++ b/Week04/decorators_burakhan_gultoplar.py @@ -0,0 +1,24 @@ +import time +import tracemalloc + +def performance(func): + def wrapper(*args, **kwargs): + tracemalloc.start() + t1 = time.perf_counter() + + result = func(*args, **kwargs) + + t2 = time.perf_counter() + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += (t2 - t1) + performance.total_mem += peak + + return result + return wrapper + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0 From 76fa55bfb4855d8c224245a885f434c530442f42 Mon Sep 17 00:00:00 2001 From: Burakhan7 <141933959+Burakhan7@users.noreply.github.com> Date: Wed, 8 Apr 2026 12:05:10 +0300 Subject: [PATCH 2/2] Update decorators_burakhan_gultoplar.py --- Week04/decorators_burakhan_gultoplar.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Week04/decorators_burakhan_gultoplar.py b/Week04/decorators_burakhan_gultoplar.py index 3c2815e8..42a1f8fd 100644 --- a/Week04/decorators_burakhan_gultoplar.py +++ b/Week04/decorators_burakhan_gultoplar.py @@ -2,23 +2,26 @@ import tracemalloc def performance(func): - def wrapper(*args, **kwargs): + def inner(*args, **kwargs): tracemalloc.start() - t1 = time.perf_counter() + start_time = time.perf_counter() - result = func(*args, **kwargs) + output = func(*args, **kwargs) - t2 = time.perf_counter() - _, peak = tracemalloc.get_traced_memory() + end_time = time.perf_counter() + current, peak_memory = tracemalloc.get_traced_memory() tracemalloc.stop() + performance.counter += 1 - performance.total_time += (t2 - t1) - performance.total_mem += peak + performance.total_time += (end_time - start_time) + performance.total_mem += peak_memory - return result - return wrapper + return output + + return inner + performance.counter = 0 -performance.total_time = 0 +performance.total_time = 0.0 performance.total_mem = 0