Table of Contents
In this example, you will learn to measure the elapsed time.
To understand this example, you should have the knowledge of the following Python programming topics:
1. Example 1: Using time module
import time start = time.time() print(23*2.3) end = time.time() print(end - start)
Output
52.9 3.600120544433594e-05
In order to calculate the time elapsed in executing a code, the time
module can be used.
- Save the timestamp at the beginning of the code
start
usingtime()
. - Save the timestamp at the end of the code
end
. - Find the difference between the end and start, which gives the execution time.
The execution time depends on the system.
2. Example 2: Using 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
Similar to Example 1, we use timer()
method from timeit
module.
timeit
provides the most accurate results.
Related posts:
Python List copy()
Python int()
Python tuple()
Python Program to Convert Kilometers to Miles
Python getattr()
Python Machine Learning Eqution Reference - Sebastian Raschka
Python String isalnum()
Python locals()
Python String zfill()
Python classmethod()
Intelligent Projects Using Python - Santanu Pattanayak
Python Program to Convert Celsius To Fahrenheit
Python Program to Differentiate Between del, remove, and pop on a List
Python Program to Extract Extension From the File Name
Python List Comprehension
Python String index()
Python Program to Multiply Two Matrices
Python Program to Check if a Number is Odd or Even
Python Set update()
Deep Learning in Python - LazyProgrammer
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
Python list()
Python Program to Find Armstrong Number in an Interval
Python Errors and Built-in Exceptions
Python Program to Shuffle Deck of Cards
Python Program to Transpose a Matrix
Python Program to Delete an Element From a Dictionary
Python String expandtabs()
Python vars()
Python isinstance()
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Represent enum