What is the difference between import outside and inside the method? what is the difference in performance?

-sharp 1
import time
s =time.time()
print(time.time())
print(time.time())
print(time.time())
print(time.time())
print(time.time())
print(format(time.time()-s,"f"))
-sharp 2
def get_time():
    import time
    print(time.time())
s = time.time()
get_time()
get_time()
get_time()
get_time()
get_time()
print(format(time.time()-s,"f"))

what is the difference in performance between the two? What"s the difference?

Local python3 output

1538428458.134572
1538428458.134617
1538428458.134623
1538428458.134628
1538428458.1346319
0.000066
1538428458.1346502
1538428458.134655
1538428458.13466
1538428458.134665
1538428458.13467
0.000027
Aug.06,2021

I don't know much about it, but your test code doesn't respond to the problem. I tried it myself

The logic of

import is as far as I know

if the currently introduced package has already been introduced, it will not be reintroduced, but its address will be copied to the current scope

simple test of py2

  

when called in a function, the package is imported multiple times, and the top import is used only once

Menu