How to measure time elapsed in Python?

0 votes
How should I use the timeit module if i want to start counting time somewhere in my code and then get the passed time. I think I am using the module wrong.

import timeit

start = timeit.timeit()
print "hello"
end = timeit.timeit()
print end - start
Dec 4, 2018 in Python by ana1504.k
• 7,870 points
914 views

1 answer to this question.

0 votes
If you just want to measure the elapsed wall-clock time between two points, you could use time.time():

import time

start = time.time()
print("hello")
end = time.time()
print(end - start)
 

The following code gives the execution time in seconds.
answered Dec 4, 2018 by SDeb
• 13,160 points

Related Questions In Python

0 votes
0 answers

how can i measure the elapsed time in python?

can you give an example? READ MORE

May 21 in Python by Waseem
• 4,480 points
28 views
0 votes
3 answers

How to get the current time in Python

FOLLOWING WAY TO FIND CURRENT TIME IN ...READ MORE

answered Apr 8 in Python by rajesh
• 1,210 points
69 views
0 votes
1 answer

How to get the current time in Python

>>> import datetime >>> datetime.datetime.now() datetime(2018, 25, ...READ MORE

answered Jul 25, 2018 in Python by Frankie
• 9,810 points
48 views
0 votes
1 answer

How to parse date/time string with timezone abbreviated name in Python?

The parse() function in dateutil can't handle ...READ MORE

answered Nov 27, 2018 in Python by Nymeria
• 3,520 points
206 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 283 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 28, 2018 in Python by SDeb
• 13,160 points
75 views
0 votes
1 answer

How do I append one string to another in Python?

If you only have one reference to ...READ MORE

answered Oct 22, 2018 in Python by SDeb
• 13,160 points
45 views