Back

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

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

1 Answer

0 votes
by (25.1k points)

You can use the time module like this:

import time

start = time.time()

print("hello")

end = time.time()

print(end - start)

 

It will give you the execution time in seconds.

If you want to get a deeper understanding of python you can watch this youtube video: 

Related questions

+8 votes
2 answers
0 votes
1 answer
asked Feb 8, 2021 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...