I'm a bit curious about how you do the timing. I think there is a flaw
in how you measured the time. I made this code and the result is
inconclusive.
## CODE: test.py
#!/usr/bin/env python
import imported
import time
from imported import *
def b():
a = 1
r = range(5000000)
t_a, t_b, t_c, t_d = 1000, 1000, 1000, 1000
for n in xrange(20):
# a - direct, no function call
start = time.time()
for _ in r:
a = 1
end = time.time()
t_A = end - start
# b - function call
start = time.time()
for _ in r:
b()
end = time.time()
t_B = end - start
# c - imported module
start = time.time()
for _ in r:
imported.c()
end = time.time()
t_C = end - start
# d - imported function
start = time.time()
for _ in r:
c()
end = time.time()
t_D = end - start
t_a = min(t_A, t_a)
t_b = min(t_A, t_b)
t_c = min(t_A, t_c)
t_d = min(t_A, t_d)
print t_a
print t_b
print t_c
print t_d
## CODE: imported.py
def c():
a = 1
## OUTPUT
# 1.02956604958
# 1.02956604958
# 1.02956604958
# 1.02956604958
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor