Find time of calculation in Python

This Python DateTime tutorial will teach you how to find the time of calculation. You can find the calculation time using the following code:

# Import the time module
import time

# Get the start time
start_time = time.time()

# Calculate the sum of 1 to 50000000
sum = 0

for i in range(1, 50000001):
    sum += i

# Get the end time
end_time = time.time()

# Calculate the total time
total_time = end_time - start_time

# Display the total time
print("Total time in seconds:", str(total_time))



Total time in seconds: 3.5105507373809814

Free learning resources: AiHintsCodeAllow

Leave a Comment

Your email address will not be published.