File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import time
2+ import tracemalloc
3+ import functools
4+
5+ def performance (func ):
6+ """
7+ Fonksiyonun performansını ölçen ve istatistiklerini saklayan dekoratör.
8+ """
9+ if not hasattr (performance , "counter" ):
10+ performance .counter = 0
11+ performance .total_time = 0.0
12+ performance .total_mem = 0
13+
14+ @functools .wraps (func )
15+ def wrapper (* args , ** kwargs ):
16+ tracemalloc .start ()
17+ start_time = time .perf_counter ()
18+ result = func (* args , ** kwargs )
19+ end_time = time .perf_counter ()
20+
21+ current_mem , peak_mem = tracemalloc .get_traced_memory ()
22+ tracemalloc .stop ()
23+
24+ performance .counter += 1
25+ performance .total_time += (end_time - start_time )
26+ performance .total_mem += peak_mem
27+
28+ return result
29+
30+ return wrapper
31+
32+ performance .counter = 0
33+ performance .total_time = 0.0
34+ performance .total_mem = 0
You can’t perform that action at this time.
0 commit comments