Usage of main()
alex23
wuwei23 at gmail.com
Fri Sep 4 02:55:37 EDT 2009
Sean DiZazzo <half.ital... at gmail.com> wrote:
> What are you using to test the scripts? I could be completely wrong,
> but I find it hard to believe that the second version is much (if any)
> faster than the first. Then again, I don't know much about the
> internals...
Sorry, Sean, unfortunately you are wrong, although it's understandable
that you've missed this.
The lookup of locally scoped references is a lot faster than that of
global ones, primarily due to the lookup order: it first checks the
local scope and then out through surrounding scopes _before_ the
global scope.
So yes, depending on the nature of your code, its quite conceivable to
find distinct performance differences between code using the __main__
idiom and code without.
More information about the Python-list
mailing list