I stumbled upon something which makes no sense. I have this python code which does 2 simple for-loops and just measures the execution time. However I discovered that the exact same code called from a function takes half of the time. Can someone explain why ?
print "no function"
start_time = time.time()
for i in range(10000):
for j in range(10000):
z = i*j
print z
print("--- %s seconds ---" % (time.time() - start_time))
# VS
def Function():
start_time = time.time()
for i in range(10000):
for j in range(10000):
z = i*j
print z
print("--- %s seconds ---" % (time.time() - start_time))
print "Function Call"
Function()
And here is the output:
no function
99980001
--- 8.89359378815 seconds ---
Function Call
99980001
--- 4.64798092842 seconds ---