File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import time
2+ import sys
3+ def performance (func ):
4+ if not hasattr (performance ,"counter" ):
5+ setattr (performance ,"counter" ,0 )
6+
7+ if not hasattr (performance ,"total_time" ):
8+ setattr (performance ,"total_time" ,0 )
9+
10+ if not hasattr (performance ,"total_mem" ):
11+ setattr (performance ,"total_mem" ,0 )
12+
13+ def _d1 ():
14+ memory_used = sys .getsizeof (func )
15+ start_time = time .time_ns ()
16+ func ()
17+ performance .counter += 1
18+ end_time = time .time_ns ()
19+ elapsed = 0
20+ elapsed = end_time - start_time
21+ performance .total_time += (int )(elapsed / 1e9 )
22+ performance .total_mem += memory_used
23+ return (performance .counter , performance .total_time , performance .total_mem )
24+
25+ return _d1
26+
27+
28+ if __name__ == "__main__" :
29+ @performance
30+ def function_to_test ():
31+ time .sleep (1 )
32+
33+ def function ():
34+ for i in range (1 ):
35+ function_to_test ()
36+ function ()
37+ print (function_to_test ())
You can’t perform that action at this time.
0 commit comments