I have a program say:
for i in xrange(10):
for p in xrange(10):
print i, p
I would like to be able to print the time in milliseconds that the program took to execute at the end of the program.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve written a small snippet that could allow you to measure the elapsed time using a context manager. Have a look at https://github.com/BaltoRouberol/timer-context-manager
Example:
It uses
timeit.default_timer(a platform specific timer function :time.timefor Unix platforms andtime.clockfor Windows platforms) to measure the wall clock time of the block.