On Friday 17 October 2008 19:50:14 David Reiss wrote:
> This is the measurement I was referencing:
> http://publists.facebook.com/pipermail/thrift/2007-August/000073.html

I ran the script in both Python 2.5.2 and 2.6 and this is what I got:

Python 2.6:

            oldstyle: 2.966 s
            newstyle: 3.455 s
    newstyle inherit: 3.453 s
    oldstyle inherit: 2.897 s
   newstyle inherit4: 3.557 s
   oldstyle inherit4: 2.970 s
newstyle + __slots__: 3.022 s

Python 2.5.2:

            oldstyle: 2.791 s
            newstyle: 5.009 s
    newstyle inherit: 5.822 s
    oldstyle inherit: 2.828 s
   newstyle inherit4: 7.977 s
   oldstyle inherit4: 2.798 s
newstyle + __slots__: 3.566 s

I guess new style attribute lookup is O(1) in Python 2.6 due to caching:

http://bugs.python.org/issue1700288
http://bugs.python.org/issue1685986
http://bugs.python.org/issue1568

and slots seem to bring oldstyle-comparable performance to newstyle.

However, I'm not sure if this benchmark is fair, since in the typical RPC 
scenario (ok, you may argue that there's never a typical scenario ;-)) one 
will end up creating tons of objects, and sending them across the network, 
rather than reusing them. I modified the script to take object creation into 
account, instantiating a class in every iteration:

Python 2.6:

            oldstyle: 5.558 s
            newstyle: 5.304 s
    newstyle inherit: 5.468 s
    oldstyle inherit: 6.077 s
   newstyle inherit4: 5.399 s
   oldstyle inherit4: 7.641 s
newstyle + __slots__: 4.367 s

Python 2.5:

            oldstyle: 5.223 s
            newstyle: 7.356 s
    newstyle inherit: 7.614 s
    oldstyle inherit: 5.673 s
   newstyle inherit4: 10.006 s
   oldstyle inherit4: 6.977 s
newstyle + __slots__: 4.981 s

Cheers.

Reply via email to