Using following code i found for loop is faster in python
import time
i = 0
st = time.time()
while i < 100_000_000:
a = 0
i += 1
print(time.time()-st)
i = 0
st = time.time()
while True:
a = 0
if i < 100_000_000:
i += 1
else:
break
print(time.time()-st)
st = time.time()
for i2 in range(100_000_000):
a = 0
print(time.time()-st)
Results
E:\Anaconda\python.exe E:/Projects/Test/t.py
14.323773622512817
14.415262937545776
9.459656000137329
Process finished with exit code 0
No comments:
Post a Comment