一、使用clock()函數,獲取毫秒級時間[1]
#include <time.h> time_t start = clock(); {statement section}//測試代碼段 time_t end = clock(); printf("the running time is :%f\n", double(end -begin)/CLOCKS_PER_SEC)
二、基於CPU級的方法,獲取微妙級時間[2,3]
LARGE_INTEGER nFreq; LARGE_INTEGER t1; LARGE_INTEGER t2; double dt; QueryPerformanceFrequency(&nFreq); QueryPerformanceCounter(&t1); {statementsection}//測試代碼段 QueryPerformanceCounter(&t2); dt = (t2.QuadPart - t1.QuadPart) / (double)nFreq.QuadPart; cout<<"Running time :"<<dt<<"ms"<<endl;