这坑人的API,根本就不精确
好不容易才找到 GetSystemTimeAsFileTime 这个API 用来获取精确时间
VOID GetSystemTimeAsFileTime(
LPFILETIME lpSystemTimeAsFileTime // pointer to a file time
// structure
);
FILETIME
The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.
看到可以获取精度到百纳秒就高兴急了,可以实现我的微妙检测。
结果坑死我了。
我用下面代码测试:
FILETIME t1, t2; LARGE_INTEGER i1, i2; GetSystemTimeAsFileTime(&t1); i1.LowPart = t1.dwLowDateTime; i1.HighPart = t1.dwHighDateTime; for (int i = 0, N = 6000000; i < N; ++i) ; GetSystemTimeAsFileTime(&t2); i2.LowPart = t2.dwLowDateTime; i2.HighPart = t2.dwHighDateTime; int t = i2.QuadPart - i1.QuadPart;
long long t1, t2; t1 = GetTickCount(); while(true) { if ((t2 = GetTickCount()) - t1 > 0) { cout << t2 - t1 << endl; t1 = t2; } }