What is more efficient?
Scott David Daniels
scott.daniels at acm.org
Mon Feb 19 01:23:32 EST 2007
Karlo Lozovina wrote:
> Let's say I have a class with few string properties and few integers, and
> a lot of methods defined for that class.
>
> Now if I have hundreds of thousands (or even more) of instances of that
> class - is it more efficient to remove those methods and make them
> separate functions, or it doesn't matter?
>
> Thanks...
>
You'd do best to define the instance variable names in __slots__,
and be sure to inherit from object. The methods don't matter (they
all hang off the class anyway). The __slots__ will save you one
reference per object for the __dict__.
--
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list