Which import mechanism is faster?
问题 1: %%timeit -n 1000000 import math math.sin(math.pi/2) 1000000 loops, best of 3: 284 ns per loop 2: %%timeit -n 1000000 from math import sin, pi sin(pi/2) 1000000 loops, best of 3: 1.01 µs per loop 回答1: There you are timing two different statements - and indeed, "common sense" has it that attribute lookup as in the first snippet should have a higher overhead than using local (in this case, global) scoped names. What is happening though, is that when one does from math import sin, pi , those