카테고리 없음

c++ 에서 실행시간 측정방법

루키나이 2008. 11. 4. 12:26

1) 밀리세컨트로 측정방법

#include < stdio.h >
#include < windows.h >

void main()
{
 int i =0 ;
 DWORD start ;
 DWORD end ;

 start = GetTickCount();

//start -- 측정하고싶은 코드 부분 --

for(i=0 ; i < 1000; i++)
 {
  printf("*"); }

//end

 end = GetTickCount();

 printf("\n실행시간 : %lf \n" , (end - start) / (double)1000 );
}

windows.h에 있는 GetTickCount를 사용.

maybe GetTickCount는  CPU시간을 밀리세컨드 단위로 리턴할것이다.

2) 다른방법

clock_t start;

clock_t end;

 

start = clock();

 

//코드부분

 

end = clock();

 

printf("%lf ms elapsed\n", end - start);