I have a a collection of functions inside a file myfile.py and I would like to add a timer print automatically for each of them: (have around 700 functions)
def myfunXXX()
mytime.start()
mytime.end()
mytime.start(): to= time.time()
mytime.end(): print(time.time() - t0)
Current solutions are :
- Add a decorator manually to all the functions.
- Add the code snippet to all the functions
Is there a way to "hack" Python and the function base definition to add those 2 functions before executing and at execution end for a set of Python functions ?
Maybe using AST and injecting some string code ?