Create two timestamps , And then subtract .
The code example is as follows :
import time
start_time = time.time()
sum = 0
for i in range(100000000):
sum += i
print(sum)
end_time = time.time()
print(" Time consuming : {:.2f} second ".format(end_time - start_time))
Output :
4999999950000000
Time consuming : 10.53 second