[XML-SIG] foo.bar vs. foo.get_bar()

uche.ogbuji@fourthought.com uche.ogbuji@fourthought.com
Fri, 05 Nov 1999 18:09:36 -0700


> > So the list of knocks against "node.parent" is now:
> > 
> > *	Probably slower
> 
> Has anyone tried this?  PyDOM includes __getattr__ and __setattr__,
> but doesn't actually use them.  As a simple test, I ran a small
> program that parses a 30K XML file into a DOM tree (as in the
> xml-howto), then prints it out (using the dump method), using PyDOM.
> 
> With __get/setattr__ the average runtime was 9.1 seconds.  With those
> methods commented out, the average runtime was 4.1 seconds, so it was
> more than twice as fast.  I wonder how much slower it would be if the
> methods were ever actually used?

Any class with __[g/s]etattr__ is automatically slower, whether or not the 
methods are actually used.  This is for a simple reason: without these hooks, 
attribute access involves basic C pointer magic within the interpreter, which 
is of course blazingly fast.  Whenever the hooks are present, the interpreter 
must invoke the hooks for every attribute access, even if it turns out the 
hooks aren't used.  As I've mentioned before, round trips from the C engine to 
Python interpreted code incur a steep performance penalty.


-- 
Uche Ogbuji
FourThought LLC, IT Consultants
uche.ogbuji@fourthought.com	(970)481-0805
Software engineering, project management, Intranets and Extranets
http://FourThought.com		http://OpenTechnology.org