获取高精度时间差(Delphi)

阅读更多

由于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).
 

你可能感兴趣的:(获取高精度时间差(Delphi))