Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (47.6k points)

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.

1 Answer

0 votes
by (106k points)

To get the execution time of  a Python program the simplest way is to use the following method:

import time 

start_time = time.time()

print("--- %s seconds ---" % (time.time() - start_time))

image

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

 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...