decorator pattern fibprev fib for num in range( )fibprevfib fibfib fibprev return fib def profile_me(fn)start_time time time(result (nend_time time time(print("[time elapsed for {}{}format(nend_time start_time)return result def get_profiled_function( )return lambda nprofile_me(fnif __name__ ="__main__" fib_profiled get_profiled_function(fibprint("fibonacci number for {}{}format(nfib_profiled( ))this method works lot better but still requires some effort when trying to profile several functionsas this causes interference with the code executing the function there has to be better way ideallywe want way to tag specific function as one to be profiledand then not worry about the call that initiates the function call we will do this using the decorator pattern the decorator pattern to decorate functionwe need to return an object that can be used as function the classic implementation of the decorator pattern uses the fact that the way python implements regular procedural functions these functions can be seen as classes with some kind of execution method in pythoneverything is an objectfunctions are objects with special __call__(method if our decorator returns an object with __call__(methodthe result can be used as function