From fc41ff51f4b20ee93d9dddf3c6ce09ba5ad70636 Mon Sep 17 00:00:00 2001 From: Burakhan7 <141933959+Burakhan7@users.noreply.github.com> Date: Mon, 5 Jan 2026 16:37:08 +0300 Subject: [PATCH] Create decorators_burakhan_gultoplar.py --- Week04/decorators_burakhan_gultoplar.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 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..2406886c --- /dev/null +++ b/Week04/decorators_burakhan_gultoplar.py @@ -0,0 +1,29 @@ +import time +import tracemalloc +from functools import update_wrapper + + +class performance: + counter = 0 + total_time = 0.0 + total_mem = 0 + + def __init__(self, fn): + self.fn = fn + update_wrapper(self, fn) + + def __call__(self, *args, **kwargs): + tracemalloc.start() + t0 = time.perf_counter() + + out = self.fn(*args, **kwargs) + + t1 = time.perf_counter() + _, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += (t1 - t0) + performance.total_mem += peak + + return out