import time
class ExecutionTimer:
def __init__(self):
self.start_time = None
self.end_time = None
def start(self):
self.start_time = time.time()
def stop(self):
self.end_time = time.time()
def get_execution_time(self):
if self.start_time is not None and self.end_time is not None:
return self.end_time - self.start_time
else:
return None
if __name__ == "__main__":
# ExecutionTimer 인스턴스 생성
timer = ExecutionTimer()
# 코드 실행 시작
timer.start()
# 여기에 코드 실행할 작업을 넣습니다.
# 예를 들어, 1부터 1000000까지의 합을 구하는 작업을 수행한다고 가정합니다.
total = 0
for i in range(1, 1000001):
total += i
# 코드 실행 종료
timer.stop()
# 실행 시간 가져오기
execution_time = timer.get_execution_time()
if execution_time is not None:
print(f"코드 실행 시간: {execution_time} 초")
else:
print("실행 시간을 가져올 수 없습니다.")
'파이썬' 카테고리의 다른 글
윈도우 화면 보호기 방지 간단 코드 (0) | 2023.09.09 |
---|---|
폴더 안에 있는 모든 파일 명을 가져오는 코드 (0) | 2023.09.04 |
실행되는 경로 기준으로 날짜 폴더를 생성 (0) | 2023.09.04 |