Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

파이썬의 time.perf_counter() 함수

<시간/>

이 튜토리얼에서는 time.perf_counter() 방법.

time.perf_counter() 메소드 초 단위의 부동 소수점 값을 반환합니다. 보자

예시

# importing the time module
import time
# printing the time
print(time.perf_counter())

출력

위의 코드를 실행하면 다음과 같은 결과를 얻을 수 있습니다.

263.3530349

time.perf_counter()를 사용할 수 있습니다. 프로그램의 실행 시간을 찾는 방법. 예를 들어 보겠습니다.

예시

# 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)

출력

위의 프로그램을 실행하면 다음과 같은 결과를 얻을 수 있습니다.

0.004171799999994619

결론

튜토리얼에서 의문점이 있으면 댓글 섹션에 언급하세요.