-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathdecorators_hatice_akgul.py
More file actions
34 lines (27 loc) · 895 Bytes
/
Copy pathdecorators_hatice_akgul.py
File metadata and controls
34 lines (27 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import time
import tracemalloc
import functools
def performance(func):
"""
Fonksiyonun performansını ölçen ve istatistiklerini saklayan dekoratör.
"""
if not hasattr(performance, "counter"):
performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0
@functools.wraps(func)
def wrapper(*args, **kwargs):
tracemalloc.start()
start_time = time.perf_counter()
result = func(*args, **kwargs)
end_time = time.perf_counter()
current_mem, 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 wrapper
performance.counter = 0
performance.total_time = 0.0
performance.total_mem = 0