Python's Performance
Piet van Oostrum
piet at cs.uu.nl
Tue Oct 11 08:37:08 EDT 2005
>>>>> Terry Hancock <hancock at anansispaceworks.com> (TH) wrote:
>TH> He's got to be talking about runtime name-binding. In
>TH> other words, when you refer to:
>TH> a.spam
>TH> the Python interpreter actually knows you labeled that attribute 'spam',
>TH> and the string is stored in a.__dict__ , so you can also access it as
>TH> getattr(a, 'spam')
>TH> etc.
>TH> I'm pretty sure this is what string "internment" is for, though, and
>TH> that such lookups are optimized out pretty much whenever possible.
In the case of getattr(a, 'spam') a string comparison for 'spam' has to be
done. AFAIK, in the case of a.spam the string 'spam' has been interned, so
that no string comparison is necessary at lookup, only a pointer
comparison. Due to hash collisions probably multiple comparisons could be
necessary.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list