由于GetTickCount精度只有10~16ms
MSDN 写道
The resolution of the GetTickCount function is limited to the resolution of the system timer, which is typically in the range of 10 milliseconds to 16 milliseconds.
当程序要更高精度时间差的话,可以用QueryPerformanceCounter和QueryPerformanceFrequency
beginTick := 0; endTick := 0; expTime := 0; QueryPerformanceCounter(beginTick); // do something... QueryPerformanceCounter(endTick); QueryPerformanceFrequency(freq); expTime := (endTick - beginTick) / freq * 1000;
不过QueryPerformanceCounter有个多CPU的问题要小心
MSDN 写道
On a multiprocessor computer, it should not matter which processor is called. However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL).
本文介绍了Windows环境下两种获取时间间隔的方法:GetTickCount和QueryPerformanceCounter。前者精度受限于系统定时器,一般为10到16毫秒;后者提供更高的时间分辨率,但需要注意多处理器系统中可能出现的问题。
1万+

被折叠的 条评论
为什么被折叠?



