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.
1 parent 71f5b39 commit 3093c16Copy full SHA for 3093c16
Week04/decorators_elifsude_yilmaz.py
@@ -0,0 +1,30 @@
1
+import time
2
+import tracemalloc
3
+from functools import wraps
4
+
5
6
+def performance(func):
7
+ @wraps(func)
8
+ def wrapper(*args, **kwargs):
9
+ start_time = time.time()
10
11
+ tracemalloc.start()
12
+ result = func(*args, **kwargs)
13
+ current, peak = tracemalloc.get_traced_memory()
14
+ tracemalloc.stop()
15
16
+ end_time = time.time()
17
18
+ performance.counter += 1
19
+ performance.total_time += (end_time - start_time)
20
+ performance.total_mem += peak
21
22
+ return result
23
24
+ return wrapper
25
26
27
+# decorator attributes
28
+performance.counter = 0
29
+performance.total_time = 0.0
30
+performance.total_mem = 0
0 commit comments