Question: Define a decorator named performance that wraps a function to return a tuple with ( 1 ) the original return value of the function and
Define a decorator named performance that wraps a function to return a tuple with the original return value of the function and the amount of time that it took. For example, we should be able to write:
@performance def adda b: return a b sumresult, timetaken add # sumresult timetaken ~
Hint: to create a decorator named fakeperformance that returns a tuple with the function call result and a string, we could do the following:
import functools def fakeperformancefunc: @functools.wrapsfunc def wrapperargskwargs: result funcargskwargs return result, "PUT THE ELAPSED TIME HERE AS A NUMBER" return wrapper
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
