// An highlighted block
import time
if __name__ == '__main__':
a = 1
b = 2
t1 = time.time()
if a == 1 and b==2:
for i in range(100000000):
c = 0
t2 = time.time()
print(t2-t1)
t1 = time.time()
if a == 0 and b == 2:
for i in range(100000000):
c = 0
t2 = time.time()
print(t2 - t1)
// An highlighted block
C:\anaconda3\python.exe "D:/Note/210511 Airsim python client/test.py"
4.788227558135986
0.0
Process finished with exit code 0
一个花了4.788s
一个花了0.0s
因为第二个在做出判断的时候就退出了,节省了很多时间。