Performance penalty for using properties?
Aahz
aahz at pythoncraft.com
Sat Mar 13 11:09:20 EST 2004
In article <slrnc55f2n.1qp.kmmcdonald at g4.gateway.2wire.net>,
Kenneth McDonald <kmmcdonald at wisc.edu> wrote:
>
>Now that I'm back to Python and all the new (to me) cool features,
>I find I'm using properties a lot, i.e. I'm defining:
>
> foo = property(fset=..., fget=...)
>
>for a number of properties, in many of my classes. I'm not using
>them for anything performance critical yet, but could see myself
>doing so in the future. Can anyone comment on the performance
>costs associated with properties vs. simple attribute lookup?
That's sort-of not the point. Yes, plain attribute lookups are going to
be faster because they don't involve a function call. OTOH, new-style
classes already pay a penalty for properties because any simple
attribute lookup on an instance requires checking the whole MRO to make
sure there isn't a property. Finally, the proper comparison is against
getter/setter methods, which properties encapsulate nicely.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"usenet imitates usenet" --Darkhawk
More information about the Python-list
mailing list