Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 5
    Interesting that you noticed in practice, I just read that this is because new-style classes, once they have found the attribute in the instance dict, have to do an additional lookup to work out whether it is a description, ie, it has a get method that needs to be invoked to get the value to be returned. Old style classes simple return the found object with no addition computations (but then do not support descriptors). You can read more in this excellent post by Guido python-history.blogspot.co.uk/2010/06/…, specifically the section on slots Commented Mar 20, 2012 at 16:58
  • 1
    doesn’t seem to be true with CPython 2.7.2: %timeit aobj.a 10000000 loops, best of 3: 66.1 ns per loop %timeit bobj.a 10000000 loops, best of 3: 53.9 ns per loop Commented Mar 24, 2012 at 22:38
  • 1
    Still faster for aobj in CPython 2.7.2 on x86-64 Linux for me. Commented Apr 5, 2012 at 12:49
  • 45
    It's probably a bad idea to rely on pure Python code for performance sensitive applications. Nobody says: "I need fast code so I'll use old-style Python classes." Numpy doesn't count as pure Python. Commented Jun 30, 2012 at 22:42
  • also in IPython 2.7.6, this isn't true. ''''477 ns vs. 456 ns per loop'''' Commented Jul 20, 2014 at 11:48