A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2008-October/082945.html below:

[Python-Dev] __getattr__ and new style classes

[Python-Dev] __getattr__ and new style classesNick Coghlan ncoghlan at gmail.com
Wed Oct 8 23:37:19 CEST 2008
Kristján Valur Jónsson wrote:
> Hello there.
> 
> I‘ve just noticed what I consider a performance problem:
> 
> Using new style classes to provide attribute-like access using
> __getattr__ is considerably slower than old style classes:  Observe:

I can't reproduce those relative numbers using SVN trunk. Using your
setup code (copied and pasted directly from your message to my
interpreter session) I got the following numbers:


>>> timeit.Timer('d.foo', s).timeit()
1.2362558841705322
>>> timeit.Timer('d2.foo', s).timeit()
1.1634600162506104
>>> timeit.Timer('d.foo', s).timeit()
1.1840031147003174
>>> timeit.Timer('d2.foo', s).timeit()
1.1554200649261475

(a slight speed advantage to the new-style class for __getattr__)

>>> timeit.Timer('d.bar', s).timeit()
0.17601609230041504
>>> timeit.Timer('d2.bar', s).timeit()
0.18697309494018555
>>> timeit.Timer('d.bar', s).timeit()
0.1711127758026123
>>> timeit.Timer('d2.bar', s).timeit()
0.1827549934387207

(very slight speed advantage to the old-style class for the unbound method)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
            http://www.boredomandlaziness.org
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4