-
[C, C++] 간단하게 시간재기dev 2014. 5. 8. 13:57
1. clock_t 를 이용할 경우
#include <time.h>using namespace std;
void main()
{clock_t beg = clock();
// 시간 잴 코드
clock_t end = clock();
long msec = end - beg; // 단위는 milliseconds, 나누기 1000 하면 seconds
}
2. GetTickCount() 를 이용할 경우 - widn32 API
#include <windows.h>using namespace std;
void main()
{int beg = GetTickCount();
// 시간 잴 코드
int end = GetTickCount();
int msec = end - beg; // 단위는 milliseconds, 나누기 1000 하면 seconds
}
+ nano seconds 단위의 time check 필요할 때 참고
http://nadeausoftware.com/articles/2012/04/c_c_tip_how_measure_elapsed_real_time_benchmarking [★★★]
http://cplus.about.com/od/howtodothingsi2/a/timing.htm
http://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx
http://stackoverflow.com/questions/275004/c-timer-function-to-provide-time-in-nano-seconds