c++利用windows函數實現計時范例
計時怎樣利用代碼實現呢?以下是為大家分享的c++利用windows函數實現計時范例,供大家參考借鑒,歡迎瀏覽!
復制代碼 代碼如下:
/pic/p>
#include
#include
#include/pic/p>
#include/pic/p>
#pragma comment(lib, "Winmm.lib") /pic/p>
/pic/p>
int main()
{ /pic/p>
time_t timeBegin, timeEnd;
timeBegin = time(NULL);
Sleep(1000);
timeEnd = time(NULL);
printf("%dn", timeEnd - timeBegin);
/pic/p>
clock_t clockBegin, clockEnd;
clockBegin = clock();
Sleep(800);
clockEnd = clock();
printf("%dn", clockEnd - clockBegin);
/pic/p>
DWORD dwBegin, dwEnd;
dwBegin = timeGetTime();
Sleep(800);
dwEnd = timeGetTime();
printf("%dn", dwEnd - dwBegin);
/pic/p>
DWORD dwGTCBegin, dwGTCEnd;
dwGTCBegin = GetTickCount();
Sleep(800);
dwGTCEnd = GetTickCount();
printf("%dn", dwGTCEnd - dwGTCBegin);
/pic/p>
LARGE_INTEGER large_interger;
double dff;
__int64 c1, c2;
QueryPerformanceFrequency(&large_interger);
dff = large_interger.QuadPart;
QueryPerformanceCounter(&large_interger);
c1 = large_interger.QuadPart;
Sleep(800);
QueryPerformanceCounter(&large_interger);
c2 = large_interger.QuadPart;
printf("本機高精度計時器頻率%lfn", dff);
printf("第一次計時器值%I64dn第二次計時器值%I64dn計時器差%I64dn", c1, c2, c2 - c1);
printf("計時%lf毫秒nn", (c2 - c1) * 1000 / dff);
return 0;
}
【c++利用windows函數實現計時】相關文章:
c和c++中實現函數回調的方法01-18
C++函數考點歸納11-24
C++函數模板11-06
C++中內聯(lián)函數的應用01-19
C++如何調用matlab函數10-12
C++調用C函數的方法02-28
C/C++函數調用的方式09-23
c++函數指針使用示例02-09
C++函數指針學習教程11-09