From 5d08ffb1ce861e8c0cf3e57b55c6b39a8d93f598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Batuhan=20Tun=C3=A7?= <58087692+Batuhaanccs@users.noreply.github.com> Date: Wed, 18 Nov 2026 23:02:38 +0300 Subject: [PATCH] Add performance decorator to track execution metrics --- Week04/decorators_batuhan_tunc.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Week04/decorators_batuhan_tunc.py diff --git a/Week04/decorators_batuhan_tunc.py b/Week04/decorators_batuhan_tunc.py new file mode 100644 index 00000000..00b8114f --- /dev/null +++ b/Week04/decorators_batuhan_tunc.py @@ -0,0 +1,24 @@ +import time +import tracemalloc + + +def performance(func): + def _performance(*args, **kwargs): + tracemalloc.start() + start_time = time.perf_counter() + result = func(*args, **kwargs) + end_time = time.perf_counter() + _, peak_mem = tracemalloc.get_traced_memory() + tracemalloc.stop() + + performance.counter += 1 + performance.total_time += end_time - start_time + performance.total_mem += peak_mem + return result + + return _performance + + +performance.counter = 0 +performance.total_time = 0 +performance.total_mem = 0