performance of dictionary lookup vs. object attributes

Andre Meyer meyer at acm.org
Fri Aug 25 04:38:10 EDT 2006


Hi all

I was wondering about the performance comparison of either using a
dictionary or an object for a large collection of "things". Therefore
I have run the attached test. I create a dictionary and an object.
Both get the same number of items/attributes, respectively. Then, for
both the values are read often (iterations).

Here are the results:

attributes 100
iterations 1000000
dic 25.515999794
obj 138.570000172

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.

kind regards
Andre
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dict_obj.py
Type: text/x-python
Size: 1433 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20060825/e6be76f4/attachment.py>


More information about the Python-list mailing list