trace.py and coverage.py

Michael Hudson mwh at python.net
Thu Jan 3 13:29:21 EST 2002


Gareth Rees <gdr at ravenbrook.com> writes:

>     3. You can make Python run faster by giving variables shorter
> names!  

I find this very hard to believe.  Can you provide evidence?

> I presume that this is because variables are looked up by name in
> the environment at run time.

Erm, not local variables (which includes function arguments).  They're
assigned a numerical index at compile time, which is what is used to
find the run time value.

> So variables with shorter names can be looked up more quickly.

Erm, not really.  Even for global and builtin objects, the strings
containing the names will be interned at compile time and have its
hash value computed only once; this means that equality testing can be
done by comparing pointers.

The only way variable names can ever so slightly affect performance is
if you manage to have names that end up in the same hash bucket in the
relavent dictionary, and this (a) is pretty unlikely (b) probably has
a neglible effect.

> Hence c, f, t, x, y in my code.

I think you need a better excuse for that :)

Cheers,
M.

-- 
  MARVIN:  Do you want me to sit in a corner and rust, or just fall
           apart where I'm standing?
                    -- The Hitch-Hikers Guide to the Galaxy, Episode 2



More information about the Python-list mailing list