Python 2 times slower than Perl

Erno Kuusela erno-news at
Tue Jul 17 18:10:11 EDT 2001

In article <87itgrmf9k.fsf at>, com-nospam at
(Christopher A. Craig) writes:

| Erno Kuusela <erno-news at> writes:
|| if you put the code in a function, it will be a fair bit faster
|| since global variable access is slower than local variable access.

| This is, in this case, incorrect.  Unless I am horribly mistaken, the
| higher cost of dealing with globals is that you first have to do a
| failed lookup in the local dictionary.  (Plus failed lookups are more
| expensive than successful ones)  

the trick is that local variables are (most of the time) not stored
in a dictionary by python. it is known at compile time whether
a given variable is global or local.

  -- erno

More information about the Python-list mailing list