Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get time of a Python program's execution?

I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.

I've looked at the timeit module, but it seems it's only for small snippets of code. I want to time the whole program.

like image 489
john2x Avatar asked Oct 12 '09 23:10

john2x


People also ask

How do I find the execution time of a Python program?

Using the DateTime module check the execution time Using the datetime module in Python and datetime. now() function to record timestamp of start and end instance and finding the difference to get the code execution time.


1 Answers

The simplest way in Python:

import time start_time = time.time() main() print("--- %s seconds ---" % (time.time() - start_time)) 

This assumes that your program takes at least a tenth of second to run.

Prints:

--- 0.764891862869 seconds --- 
like image 70
rogeriopvl Avatar answered Oct 06 '22 00:10

rogeriopvl