Run Python3 decorator of time

. 1  DEF Timer (function):
 2      "" " 
. 3      decorator function Timer
 . 4      : param function: the function desired timing
 . 5      : return:
 . 6      " "" 
. 7  
. 8      DEF warpper (* args, ** kwargs):
 . 9          TIME_START = the time.time ()
 10          RES = function (* args, ** kwargs)
 . 11          cost_time the time.time = () - TIME_START
 12 is          Print ( " [% s] run time: sec] [% s " % (function. the __name__ , cost_time))
 13 is          return RES
 14 
15     return wrapper
16 
17 
18 @timer
19 def main():
20     time.sleep(1)
21 
22 
23 if __name__ == '__main__':
24     main()

 

Guess you like

Origin www.cnblogs.com/JentZhang/p/12651596.html