Find out time it took for a python script to complete execution

0 votes

I am working with the following code in a python script:

def fun(): 
  #Code here

fun()

I want to execute this script and also find out how much time it took to execute in minutes. How do I find out how much time it took for this script to execute? Can anyone help me with this?

Aug 6, 2019 in Python by ana1504.k
• 7,910 points
434 views

1 answer to this question.

0 votes

You can try the following code and see if it works:

from datetime import datetime
startTime = datetime.now()

#do something

#Python 2: 
print datetime.now() - startTime 

#Python 3: 
print(datetime.now() - startTime)
answered Aug 6, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

How to write a python script for downloading a video from YouTube and saving it to a directory?

First download pytube using the following code  pip ...READ MORE

answered Sep 4, 2019 in Python by Neel
• 3,020 points
2,419 views
0 votes
1 answer

How to handle AssertionError in Python and find out which line or statement it occurred on?

Use the traceback module: import sys import traceback try: ...READ MORE

answered Dec 18, 2018 in Python by charlie_brown
• 7,720 points
5,367 views
0 votes
1 answer

How to find out which functions a Python module contains?

Yes, you can do this. Python allows ...READ MORE

answered May 14, 2019 in Python by Raj
1,463 views
0 votes
1 answer

Is it possible to print all the modules imported in a python script?

Since I am using Python 3.6, I ...READ MORE

answered Jul 3, 2019 in Python by Neel
• 3,020 points
2,878 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,061 views
0 votes
1 answer
+1 vote
1 answer

How to Profile a script in Python

Python includes a profiler called cProfile. It ...READ MORE

answered Nov 21, 2018 in Python by SDeb
• 13,300 points
1,434 views
0 votes
1 answer

Shorter way to write a Python for loop

You can use the enumerate iterator: for i, ...READ MORE

answered Jan 17, 2019 in Python by SDeb
• 13,300 points
1,781 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP