2012년 10월 9일 화요일

[C++] 실행 시간 체크


1. 소스 내용
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int main() {

 clock_t startTime, endTime;

 startTime = clock();

 int x = 0;

 for (x; x < INT_MAX; x) {
  x += 1;
 }

 cout << "x = " << x << endl;
 endTime = clock();
 cout << "running time " << (float) (endTime - startTime) / CLOCKS_PER_SEC << "sec"
   << endl;

 return 0;
}

2. 실행결과 

x = 2147483647
running time 7.293sec


댓글 없음 :

댓글 쓰기