Performance impact of using decorators

Fredrik Lundh fredrik at pythonware.com
Fri Mar 10 17:53:01 CET 2006


"vinjvinj" wrote:

> I'm building an application with cherrypy and have started using
> decorators quite extensively. A lot of my exposed functions look like:
>
> @expose
> @startTransactrionAndBuildPage
> @partOfTabUi(tabId)
> @convert(arg1=int, arg2=str)
> def do_main_page(self, arg1, arg2):
>    some code
>
> I've become really fond of decorators and use them quite a lot. I've
> also ready that function calls are expensive in python. In the above
> example, does the interpreter call 5 different functions?

the decorators themselves are only called when the function is defined.

what happens at runtime depends on what the decorators do (in pretty
much the same way as the output and execution time for this script

    x = lambda: return "hello"
    x = foo(x)
    x = fie(x)
    x = fum(x)
    print x()

depends on what the foo, fie, and fum functions do...)

</F>






More information about the Python-list mailing list