python check how long action took time code example
Example 1: python calculate time taken
import time
start = time.process_time()
print(time.process_time() - start)
Example 2: how to record execution time in python
import time
start = time.time()
print("hello")
end = time.time()
print(end - start)
Example 3: how to time a python script
from datetime import datetime
start = datetime.now()
print(datetime.now() - start)
Example 4: python how to measure code run in time
import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))