Why no list heritable type?

Jp Calderone exarkun at divmod.com
Fri Dec 17 20:39:30 CET 2004

On Fri, 17 Dec 2004 13:24:43 -0600, Mike Meyer <mwm at mired.org> wrote:
>Jeff Shannon <jeff at ccvcorp.com> writes:
> > Sion Arrowsmith wrote:
> > Additionally, as I understand it UserList and UserDict are implemented
> > entirely in Python, which means that there can be significant
> > performance differences as well.
> Actually, UserList and UserDict are just wrappers around the builtin
> types. So the performance hit is one Python function call - pretty
> much neglible. But new code should still subclass the builtins.

  Only tangentially related, but I'll bring it up anyway: method calls 
are more expensive than function calls:

    exarkun at boson:~$ timeit -s "def foo(): pass" "foo()"
    1000000 loops, best of 3: 0.382 usec per loop
    exarkun at boson:~$ timeit -s "class Foo:
        def foo(self): pass
    f = Foo()" "f.foo()"
    1000000 loops, best of 3: 0.611 usec per loop
    exarkun at boson:~$ 

  This is due to the attribute lookup as well as the creation and 
destruction of a bound method object for each call.


More information about the Python-list mailing list