performance of dictionary lookup vs. object attributes

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Aug 25 08:15:04 EDT 2006


Andre Meyer:
> Is the test meaningful and are you surprised by the results?
> I am, actually, because I would have assumed that attribute access
> with an object should be faster because lookup can be precompiled.

The results seem okay. Python is a dynamic language, object attributes
(and methods, etc) are kept inside a dict, where you can add and remove
them when you like. So using a dict is faster.
You can also take a look at __slots__

Bye,
bearophile




More information about the Python-list mailing list