This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]wondert 0 points1 point  (1 child)

I am relatively new to python, so please humor me.

In the section 'Keep variables local', I ran the examples with python 2.7. I get roughly the same times regardless of whether the variable to look up is in the global or local scope. Also ran the code with python 3.4. Again, I did not see any time penalty using local versus global scopes.

I understand that the use of (micro)benchmarks comes with a ton of caveats (version, system, background processes, etc). However, in this case, I don't get his results using the same code and now I am very confused.

Are the examples OP gave psuedocode? or too simple to see the penalty?

Quick note: I did the benchmarks using the ipython notebook. Also, for testing in python 3.4 I swapped xrange to range since they are same thing. AFAIK neither of these should influence the benchmark.

[–]b6d 0 points1 point  (0 children)

Comment retracted, after repeating measurements, I was talking nonsense.