- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
# importing the time module import time # printing the time print(time.perf_counter())
If you run the above code, then you will get the following result.
We can use the time.perf_counter() method to find the execution time of a program. Let's see an 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)
If you execute the above program, then you will get the following result.
If you have any doubts in the tutorial, mention them in the comment section.
- Iterator function in Python
- Calendar function in Python
- Function Annotations in Python
- Function Decorators in Python?
- vars() function in Python
- isdisjoint() function in Python
- join() function in Python
- id() function in Python
- Union() function in Python
- issubset() function in Python
- Help function in Python
- Sorted() function in Python
- sum() function in Python
- time.process_time() function in Python
- ldexp() function in Python