subclasses that provide expected methods can often provide similar generalization routes as well test your knowledgeanswers here' one way to code the first question' solutionand its output (though some methods may run too fast to register reported timethe trick lies in replacing nested classes with nested functionsso the self argument is not the decorator' instanceand assigning the total time to the decorator function itself so it can be fetched later through the original rebound name (see the section "state information retention optionsof this for details--functions support arbitrary attribute attachmentand the function name is an enclosing scope reference in this contextif you wish to expand this furtherit might be useful to also record the best (minimumcall time in addition to the total timeas we did in ' timer examples ""file timerdeco py ( xcall timer decorator for both functions and methods ""import time def timer(label=''trace=true)on decorator argsretain args def ondecorator(func)on @retain decorated func def oncall(*args**kargs)on callscall original start time clock(state is scopes func attr result func(*args**kargselapsed time clock(start oncall alltime +elapsed if traceformat '% % fvalues (labelfunc __name__elapsedoncall alltimeprint(format valuesreturn result oncall alltime return oncall return ondecorator 've coded tests in separate file here to allow the decorator to be easily reused""file timerdeco-test py ""from __future__ import print_function from timerdeco import timer import sys force list if sys version_info[ = else (lambda xxprint(''test on functions test your knowledgeanswers