loop performance in global namespace (python-2.6.1)

P

Poor Yorick

In the following snippet, the loop in the global namespace takes twice as long
as the loop in the function namespace. Why?

limit = 50000000

def f1():
counter = 0
while counter < limit:
counter += 1
time1 = time.time()
f1()
print(time.time() - time1)
print('number of locals: ', len(locals()))

time1 = time.time()
counter = 0
while counter < limit:
counter += 1
print(time.time() - time1)
print('number of locals: ', len(locals()))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top