| Store | Cart

Don't use __slots__ (was Re: performance of dictionary lookup vs. object attributes)

From: Aahz <a...@pythoncraft.com>
25 Aug 2006 07:34:50 -0700
In article <1156508104.583914.323700 at b28g2000cwb.googlegroups.com>,
 <bearophileHUGS at lycos.com> wrote:
>Andre Meyer:>>>> Is the test meaningful and are you surprised by the results?>> I am, actually, because I would have assumed that attribute access>> with an object should be faster because lookup can be precompiled.>>The results seem okay. Python is a dynamic language, object attributes>(and methods, etc) are kept inside a dict, where you can add and remove>them when you like. So using a dict is faster.>You can also take a look at __slots__

Taking a look at __slots__ is fine as long as you don't actually use
them.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan

Recent Messages in this Thread
bear...@lycos.com Aug 25, 2006 12:15 pm
Aahz Aug 25, 2006 02:34 pm
Gabriel Genellina Aug 25, 2006 03:23 pm
s...@pobox.com Aug 25, 2006 03:33 pm
Patrick Maupin Aug 26, 2006 07:51 pm
s...@pobox.com Aug 26, 2006 08:28 pm
Carl Banks Aug 26, 2006 09:16 pm
Dieter Maurer Aug 28, 2006 07:26 pm
Patrick Maupin Aug 29, 2006 12:30 am
Jarek Zgoda Aug 26, 2006 08:35 pm
Patrick Maupin Aug 26, 2006 08:51 pm
Patrick Maupin Aug 26, 2006 08:49 pm
bear...@lycos.com Aug 25, 2006 05:38 pm
Peter Otten Aug 25, 2006 12:48 pm
Fredrik Lundh Aug 25, 2006 01:03 pm
Jacob Hallen Aug 27, 2006 11:59 pm
Patrick Maupin Aug 28, 2006 12:52 am
David Isaac Aug 28, 2006 03:49 am
Antoon Pardon Aug 29, 2006 07:07 am
Messages in this thread