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.