From 2f22d991789d6bdc2a61750ab38c87f0e2df21e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=BC=C5=9Fra=20Pehlivanlar?= Date: Tue, 23 Dec 2025 17:41:22 +0300 Subject: [PATCH] Add performance decorator --- Week04/decorators_busra_pehlivanlar.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Week04/decorators_busra_pehlivanlar.py diff --git a/Week04/decorators_busra_pehlivanlar.py b/Week04/decorators_busra_pehlivanlar.py new file mode 100644 index 00000000..a259484b --- /dev/null +++ b/Week04/decorators_busra_pehlivanlar.py @@ -0,0 +1,21 @@ +import time +import sys + +def performance(func): + def wrapper(*args, **kwargs): + start_t = time.perf_counter() + + result = func(*args, **kwargs) + + end_t = time.perf_counter() + + performance.counter += 1 + performance.total_time += (end_t - start_t) + performance.total_mem += sys.getsizeof(result) + + return result + return wrapper + +performance.counter = 0 +performance.total_time = 0.0 +performance.total_mem = 0