操作系统:win2000
工具: vc6.0......
for (;;)
{
start = timeGetTime(); while ((end = timeGetTime()-start)<4)
{
if (NULL!=PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
end = timeGetTime();
end = start - end;
}我用多媒体时钟,限制这段程序的时间。逻辑上来讲应该是在end大于4的时候退出,但是我多次调试,start设置一个断点, 第二个end处设置一个断点。end最后的结果不是15就是16。我想原因是不是系统问题呢?
下面这段是我摘录msdn上的
DWORD GetTickCount(VOID)Parameters
This function has no parameters. Return Values
The return value is the number of milliseconds that have elapsed since the system was started. Res
The following table describes the resolution of the system timer. System Resolution
Windows NT 3.5 and later The system timer runs at approximately 10ms.
Windows NT 3.1 The system timer runs at approximately 16ms.
Windows 95 and later The system timer runs at approximately 55ms. 我想精确到4毫秒。好像不行是吗?
工具: vc6.0......
for (;;)
{
start = timeGetTime(); while ((end = timeGetTime()-start)<4)
{
if (NULL!=PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
end = timeGetTime();
end = start - end;
}我用多媒体时钟,限制这段程序的时间。逻辑上来讲应该是在end大于4的时候退出,但是我多次调试,start设置一个断点, 第二个end处设置一个断点。end最后的结果不是15就是16。我想原因是不是系统问题呢?
下面这段是我摘录msdn上的
DWORD GetTickCount(VOID)Parameters
This function has no parameters. Return Values
The return value is the number of milliseconds that have elapsed since the system was started. Res
The following table describes the resolution of the system timer. System Resolution
Windows NT 3.5 and later The system timer runs at approximately 10ms.
Windows NT 3.1 The system timer runs at approximately 16ms.
Windows 95 and later The system timer runs at approximately 55ms. 我想精确到4毫秒。好像不行是吗?
解决方案 »
- 这种情况,如何做数据访问互斥为好,重点是速度第一!
- 请问:SetItemText无法修改第0列的内容
- 一个文件流错误
- 关于DirectX
- 如何将一个TreeView类插入到另外一个视图中?
- [讨论]关于鼠标拖动选择item的问题
- 急急急!我们使用别人的控件,在调用控件的redrawwindow后要在控件窗口上画些我们自己的东西,但由于我们无法判断控件重画已经完成,因此
- I/O completion port如何翻译
- 请教高手:vc中那些函数必须成对
- 急急急!有关注册表操作记事本文本文档的默认显示图标的问题
- 高手来说说:对于一个组件,什么时候应该是做成动态连接库,而又什么时候该做成COM呢?
- 能不能不写代码实现程序启动任务栏图标的隐藏啊,
class CTimeCounter
{
public:
CTimeCounter(int nScaleSecond = 1000)
{
m_nScaleSecond = nScaleSecond;
Begin();
}
void Begin()
{
QueryPerformanceFrequency(&m_nFreq);
QueryPerformanceCounter(&m_nBeginTime);
}
__int64 End()
{
LARGE_INTEGER nEndTime;
QueryPerformanceCounter(&nEndTime);
return (__int64)(nEndTime.QuadPart - m_nBeginTime.QuadPart)*m_nScaleSecond/m_nFreq.QuadPart;
}
protected:
int m_nScaleSecond;
LARGE_INTEGER m_nFreq;
LARGE_INTEGER m_nBeginTime;
};
CTimeCounter tc; // 或者CTimeCounter tm(1000000); 精确到1/1000000秒
// 你的代码
__int64 nCount = tc.End();
tc.Begin(); //重新开始计数
....nCount = tc.End();
DWORD st,et;//起始时间,终止时间
_asm{
RDTSC
mov st,eax
}
<..你的代码..>
_asm{
RDTSC
mov et,eax
}