We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents f46ae7b + f1ff5f3 commit 024949bCopy full SHA for 024949b
Week04/decorators_ufuk_dilek.py
@@ -0,0 +1,21 @@
1
+import time
2
+import tracemalloc
3
+
4
5
+def performance(func):
6
+ performance.counter = 0
7
+ performance.total_time = 0
8
+ performance.total_mem = 0
9
10
+ def wrapper(*args, **kwargs):
11
+ tracemalloc.start()
12
+ time1 = time.time()
13
+ result = func(*args, **kwargs)
14
+ time2 = time.time()
15
+ current, peak = tracemalloc.get_traced_memory()
16
+ tracemalloc.stop()
17
+ performance.counter += 1
18
+ performance.total_time += time2 - time1
19
+ performance.total_mem += peak
20
+ return result
21
+ return wrapper
0 commit comments