Why is python For for Loop so slow?

I have tested a for in

performance loop in python. It contains only loop and plus operations. But it takes about 0.5 seconds. How can I make it faster?

import time

start_time = time.time()

val = -1000000
for i in range(2000000):
    val += 1

elapsed_time = time.time() - start_time

print(elapsed_time) # 0.46402716636657715

      

+3


source to share





All Articles