How can I return a value from a function decorator and the function itself?
I want to time how long a function takes to execute by using a decorator. My issue is that I want to 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 n=int(input('Please enter your number: ')) @measure_time def
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.