如何使用QueryPerformanceCounter?我最近决定,我的计时器类需要从使用毫秒改为微秒,经过一些研究后,我认为QueryPerformanceCounter可能是我最安全的赌注。(对.的警告Boost::Posix它可能不能在Win 32 API上工作,这让我有点犹豫)。但是,我不太确定如何实现它。我所做的就是管它叫什么GetTicks()我正在使用的esque函数,并将其分配给Timer的startingTicks变量。然后,为了找出传递的时间,我只需将函数的返回值从startingTicks,当我重置计时器时,我只需再次调用函数并将startingTick分配给它。不幸的是,从我看到的代码来看,它并不像调用QueryPerformanceCounter(),我不知道我应该通过什么作为它的论点。
3 回答
慕哥9229398
TA贡献1877条经验 获得超6个赞
/** Use to init the clock */#define TIMER_INIT \ LARGE_INTEGER frequency; \ LARGE_INTEGER t1,t2; \ double elapsedTime; \ QueryPerformanceFrequency(&frequency);/** Use to start the performance timer */#define TIMER_START QueryPerformanceCounter(&t1);/** Use to stop the performance timer and output the result to the standard stream. Less verbose than \c TIMER_STOP_VERBOSE */#define TIMER_STOP \ QueryPerformanceCounter(&t2); \ elapsedTime=(float)(t2.QuadPart-t1.QuadPart)/frequency.QuadPart; \ std::wcout<<elapsedTime<<L" sec"<<endl;
TIMER_INIT{ TIMER_START Sleep(1000); TIMER_STOP}{ TIMER_START Sleep(1234); TIMER_STOP}
1.00003 sec 1.23407 sec
- 3 回答
- 0 关注
- 1139 浏览
添加回答
举报
0/150
提交
取消