How to measure the elapsed time in Python

0 min read 48 words

Option 1 - using the time module

import time

start = time.time()

print(23*2.3)

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

Output:

52.9
3.600120544433594e-05

Option 2 - using the timeit module

from timeit import default_timer as timer

start = timer()

print(23*2.3)

end = timer()
print(end - start)

Output:

52.9
6.355400000000039e-05
Tags:
Andrew
Andrew

Andrew is a visionary software engineer and DevOps expert with a proven track record of delivering cutting-edge solutions that drive innovation at Ataiva.com. As a leader on numerous high-profile projects, Andrew brings his exceptional technical expertise and collaborative leadership skills to the table, fostering a culture of agility and excellence within the team. With a passion for architecting scalable systems, automating workflows, and empowering teams, Andrew is a sought-after authority in the field of software development and DevOps.

Tags

Recent Posts