请教VC++高手 如何输出高精度时间差

来源:百度知道 编辑:UC知道 时间:2024/09/12 21:18:23
分别取程序的起止时间,做差,得到以秒为单位的时间差
但精度还不够,我想将这个时间差精度到0.0001秒,请问可以实现吗?
具体应该怎么做?谢谢

晕了,想钱想疯了也就算了,百度的分数也嫌多嫌少的,开了眼了.
楼主到MSDN里看下这两个函数:
BOOL QueryPerformanceFrequency(LARGE_INTEGER* lpFrequency);
BOOL QueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount);
另外给你个实现类:
class CStopwatch {
public:
CStopwatch() { QueryPerformanceFrequency(&m_liPerfFreq); Start();}
void Start() { QueryPerformanceCounter(&m_liPerfStart); }
__int64 Now() const {
LARGE_INTEGER liPerfNow;
QueryPerformanceCounter(&liPerfNow);
return (((liPerfNow.QuadPart - m_liPerfStart.QuadPart) * 1000) / m_liPerfFreq.QuadPart);
}
private:
LARGE_INTEGER m_liPerfFreq;
LARGE_INTEGER m_liPerfStart;
};
在Now函数里,有个乘数是1000,目的是让Now返回的时间为毫秒。
使用:
CStopwatch stopwatch;
//do the work that would take long time;
__int64 qwElapsedTime = stopwatch.Now();
//qwElapsedTime indicates how long the work has spent;
注意,因为是高精度时间,因此,你要做的工作应该是短期内能完成的工作,时间太长,误差会特别大,因为线程有占用时间片的因素存在。

LARGE_INTEGER litmp ;
LO