这里用到了两个函数QueryPerformanceFrequency和QueryPerformanceCount,分别是获取频率和个数,而个数/频率=时间(时间为秒)
BOOL QueryPerformanceFrequency(LARGE_INTEGER *lpFrequency); 高精度的频率
QueryPerformanceCounter:检索高分辨率性能计数器的当前值
The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter, if one exists.
BOOL QueryPerformanceCounter(
LARGE_INTEGER *lpPerformanceCount // pointer to counter value
);
Parameters
lpPerformanceCount
Pointer to a variable that the function sets, in counts, to the current performance-counter value. If the installed hardware does not support a high-resolution performance counter, this parameter can be to zero.
Return Values
If the installed hardware supports a high-resolution performance counter, the return value is nonzero.
If the installed hardware does not support a high-resolution performance counter, the return value is zero.
计算纳秒
__int64 c1, c2;
LARGE_INTEGER large_interger;
double dff;
QueryPerformanceFrequency(&large_interger);
dff = large_interger.QuadPart;
QueryPerformanceCounter(&large_interger);
c1 = large_interger.QuadPart;
//耗时的代码。。。。
QueryPerformanceCounter(&large_interger);
c2 = large_interger.QuadPart;
printf("sync time:%lf(us)\n",(c2 - c1)*1000000/dff);