Skip to content

Commit a6d7a9a

Browse files
authored
Merge pull request canbula#739 from Zeyneepsudee/patch-4
Implement performance decorator for functions Zeynep Sude
2 parents 1e61289 + 831f12e commit a6d7a9a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import time
2+
import tracemalloc
3+
4+
5+
def performance(func):
6+
def wrapper(*args, **kwargs):
7+
performance.counter += 1
8+
tracemalloc.start()
9+
start = time.perf_counter()
10+
result = func(*args, **kwargs)
11+
performance.total_time += time.perf_counter() - start
12+
performance.total_mem += tracemalloc.get_traced_memory()[1]
13+
tracemalloc.stop()
14+
return result
15+
return wrapper
16+
17+
18+
performance.counter = 0
19+
performance.total_time = 0
20+
performance.total_mem = 0

0 commit comments

Comments
 (0)