From a1a5a9f808ec068a6b23f0698f37c1800320a336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dilara=20A=C4=9Fa=C3=A7?= <162055171+dilaraagac@users.noreply.github.com> Date: Mon, 5 Jan 2026 10:27:13 +0300 Subject: [PATCH] Add performance decorator to track execution metrics --- Week04/decorators_dilara_agac.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Week04/decorators_dilara_agac.py diff --git a/Week04/decorators_dilara_agac.py b/Week04/decorators_dilara_agac.py new file mode 100644 index 00000000..54edae42 --- /dev/null +++ b/Week04/decorators_dilara_agac.py @@ -0,0 +1,27 @@ +import time +import tracemalloc + + +def performance(func): + def wrapper(*args, **kwargs): + tracemalloc.start() + start_time = time.time() + + result = func(*args, **kwargs) + + end_time = time.time() + current, peak = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += end_time - start_time + performance.total_mem += peak + + return result + + return wrapper + + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0