#include <stdio.h>
#include <time.h>

int main( void )
{
  clock_t startTime, endTime;
  double nProcessExcuteTime;
  startTime = clock(); /*현재 시각을 구한다.*/
 
  /*여기에 코딩해주세요*/
 
  endTime = clock(); /*현재 시각을 구한다.*/
 
  nProcessExcuteTime = ( (double)(endTime - startTime) ) / CLOCKS_PER_SEC;
 
  printf("Excute time: %f\n", nProcessExcuteTime);
  return 0;
 
}


//////////////////////////////////////////////////////////////////////////
// High-resolution performance counter를 이용하여 코드의 수행 시간을 측정할 수 있다.
// 사용하는 방법은 다음과 같다.

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

int main(int argc, char **argv)
{
  LARGE_INTEGER liCounter1, liCounter2, liFrequency;
 
  // 주파수(1초당 증가되는 카운트수)를 구한다.
  QueryPerformanceFrequency(&liFrequency);
 
  // 코드 수행 전 카운트 저장
  QueryPerformanceCounter(&liCounter1);
 
  // 특정 코드 수행... 생략
 
  // 코드 수행 후 카운트 저장
  QueryPerformanceCounter(&liCounter2);
 
  // 수행 시간 계산값 출력
  printf("수행 시간 = %f 초\n", (double)(liCounter2.QuadPart - liCounter1.QuadPart) / (double)liFrequency.QuadPart);
 
  return 0;
}


//////////////////////////////////////////////////////////////////////////
// 어셈블리를 이용해서 시간 측정하는 방법

__int64 nStartcount;
_asm rdtsc               
_asm lea ebx, nStartcount         
_asm mov dword ptr [ebx], eax   
_asm mov dword ptr [ebx+4], edx

// 연산 과정..
for(int i = 0; i < 200000000; i++)
{
  i++;
  i--;
}

__int64 nEndcount;
_asm rdtsc                     
_asm lea ebx, nEndcount         
_asm mov dword ptr [ebx],   eax
_asm mov dword ptr [ebx+4], edx


double nTime = (nEndcount - nStartcount) / 2000000.0;
CString strMsg;
strMsg.Format("%f m-sec", nTime);
AfxMessageBox( strMsg );
 
2006/05/13 22:42 2006/05/13 22:42

글 걸기 주소 : 이 글에는 트랙백을 보낼 수 없습니다

덧글을 달아 주세요