Python 2 times slower than Perl

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


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

| Erno Kuusela <erno-news at erno.iki.fi> 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