Calculate Python elapsed time in milliseconds

Below is the python code that will print total elpased time or code execution time of an empty for loop of 1000.

Python code to measure elapsed time

import time
# capture start time
start_time = time.time()
for i in range(1000):
  i = i + 1
# capture end time
end_time = time.time()
# calculate elapsed time
elapsed_time = end_time - start_time
print ("Code execution time in seconds is ",elapsed_time)
elapsed_time_milliSeconds = elapsed_time*1000
print("code elapsed time in milliseconds is ",elapsed_time_milliSeconds)

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps

Leave a Reply

Your email address will not be published. Required fields are marked *