2013年9月12日 星期四

C++ Get system time

//millisecond
#include
clock_t CPU_Time_S, CPU_Time_E;    //Start, End
.
.
CPU_Time_S = clock();
xxx
xxx
xxx
CPU_Time_E = clock();
printf("Time: %fs\n", ((double)CPU_Time_E - CPU_Time_L) / CLOCKS_PER_SEC);


//microsecond
#include
LARGE_INTEGER begin, einde, freq;
QueryPerformanceFrequency(&freq);        //Get the high resolution counter's accuracy
.
.
.
QueryPerformanceCounter(&begin);        //Get start time
xxx
xxx
xxx
QueryPerformanceCounter(&einde); //Get end time
printf("Time:%fs\n", ((double)(einde.QuadPart - begin.QuadPart)) / freq.QuadPart);

沒有留言:

張貼留言