How can I return a value from a function decorator and from the function itself?
I want to time how long a function takes to execute by using a decorator. My issue is that I want the decorator to return the time value it measured along with the return value of the function. How can I achieve this? Another thing is that I expect the time taken to execute the function to be less than 1 second for small input values. However it shows more time than that. What could cause this? def measure_time(func): def wrapper(): import timeit time = timeit.timeit('func()', globals={'func':func}, number=1) return time return wrapper @measure_time def get_num(): listt = [] for i in range(n+1
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.