Skip to content

Commit 8137b3c

Browse files
authored
Merge pull request #704 from beytullaharslannn/patch-4
Add performance decorator with memory and time tracking
2 parents 683e73b + 7bd9b07 commit 8137b3c

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import time
2+
import tracemalloc
3+
4+
def performance(func):
5+
if not hasattr(performance, 'counter'):
6+
performance.counter = 0
7+
performance.total_time = 0.0
8+
performance.total_mem = 0.0
9+
def wrapper(*args, **kwargs):
10+
# 1. Ölçümleri Başlat
11+
tracemalloc.start()
12+
start_time = time.perf_counter()
13+
14+
# 2. Asıl Fonksiyonu Çalıştır
15+
result = func(*args, **kwargs)
16+
17+
# 3. Ölçümleri Bitir
18+
end_time = time.perf_counter()
19+
current_mem, peak_mem = tracemalloc.get_traced_memory()
20+
tracemalloc.stop()
21+
22+
# 4. İstatistikleri Güncelle
23+
performance.counter += 1
24+
performance.total_time += (end_time - start_time)
25+
performance.total_mem += peak_mem
26+
27+
return result
28+
wrapper.__name__ = func.__name__
29+
wrapper.__doc__ = func.__doc__
30+
31+
return wrapper

0 commit comments

Comments
 (0)