
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
time.perf_counter() function in Python
In this tutorial, we are going to learn about the time.perf_counter() method.
The method time.perf_counter() returns a float value of time in seconds. Let's see an
Example
# importing the time module import time # printing the time print(time.perf_counter())
Output
If you run the above code, then you will get the following result.
263.3530349
We can use the time.perf_counter() method to find the execution time of a program. Let's see an example.
Example
# importing the time module import time # program to find the prime number def is_prime(number): for i in range(2, number): if number % i == 0: return False return True if __name__ == '__main__': number = 17377 start_time = time.perf_counter() is_prime(number) end_time = time.perf_counter() # printing the executing time by difference print(end_time - start_time)
Output
If you execute the above program, then you will get the following result.
0.004171799999994619
Conclusion
If you have any doubts in the tutorial, mention them in the comment section.
- Related Articles
- Python counter and dictionary intersection example
- Counter Size and Counter Overflow
- time() function in PHP
- How to write a function to get the time spent in each function in Python?
- Scintillation Counter
- What is the difference between Synchronous Counter and Asynchronous Counter in computer architecture?
- SELECT increment counter in MySQL?
- Design Hit Counter in C++
- Program counter (PC) in 8085 Microprocessor
- CSS counter-increment property
- CSS counter-reset property
- Counter-Culture: A Revolution
- Time Functions in Python?
- Adding Time in Python
- Do recursive functions in Python create a new namespace each time the function calls itself?
- Python dictionary, set and counter to check if frequencies can become same

Advertisements