我通过提供自进程启动以来的微秒数来实现了QueryPerformanceCounter。
BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount)
{
gettimeofday(¤tTimeVal, NULL);
performanceCount->QuadPart = (currentTimeVal.tv_sec - startTimeVal.tv_sec);
performanceCount->QuadPart *= (1000 * 1000);
performanceCount->QuadPart += (currentTimeVal.tv_usec - startTimeVal.tv_usec);
return true;
}
这个,再加上
QueryPerformanceFrequency()
返回一个恒定的1000000作为频率,在我的机器上运行良好,并给我一个包含自程序启动以来的uSeconds
的64位变量。那么,这个可移植吗?我不想发现它在内核以某种方式编译时工作方式不同之类的情况。不过,如果除了Linux之外的其他系统不可移植,我可以接受。