File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import time
2
+ import tracemalloc
3
+
4
+
5
+ def performance (fn ):
6
+ performance .counter = 0
7
+ performance .total_time = 0.0
8
+ performance .total_mem = 0
9
+
10
+ def wrapper (* args , ** kwargs ):
11
+
12
+ start_time = time .time ()
13
+ tracemalloc .start ()
14
+
15
+
16
+ result = fn (* args , ** kwargs )
17
+
18
+
19
+ end_time = time .time () - start_time
20
+ current_mem , peak_mem = tracemalloc .get_traced_memory ()
21
+
22
+ tracemalloc .stop ()
23
+
24
+
25
+ performance .counter += 1
26
+ performance .total_time += end_time
27
+ performance .total_mem += peak_mem
28
+
29
+
30
+ print (f"Execution { performance .counter } :" )
31
+ print (f"Time: { end_time :.6f} seconds" )
32
+ print (f"Peak Memory Usage: { peak_mem / 1024 :.2f} KB\n " )
33
+
34
+ return result
35
+
36
+ return wrapper
You can’t perform that action at this time.
0 commit comments