I can not figure out how to write a decorator to detect the execution time of the function generator. For an ordinary function, everything is clear:
def decor(func): def wrapper(*args,**kwargs): time_start = time.time() f = func(*args,**kwargs) time_finish = time.time()-time_start print(time_finish) return f return wrapper
However, if you apply this to the generator, returns, as far as I understand, not the execution time, but the creation time of the generator object.
I found this solution:
t1 = timeit.Timer(stmt="list(f(50))", setup="from __main__ import f") print t1.timeit()
But I want to understand how to write. I understand that it is necessary to sum up the execution time for all the elements of the generator, but how to do it - I do not think about it.