如何使用QueryPerformanceCounter?我最近決定,我的計(jì)時(shí)器類需要從使用毫秒改為微秒,經(jīng)過一些研究后,我認(rèn)為QueryPerformanceCounter可能是我最安全的賭注。(對.的警告Boost::Posix它可能不能在Win 32 API上工作,這讓我有點(diǎn)猶豫)。但是,我不太確定如何實(shí)現(xiàn)它。我所做的就是管它叫什么GetTicks()我正在使用的esque函數(shù),并將其分配給Timer的startingTicks變量。然后,為了找出傳遞的時(shí)間,我只需將函數(shù)的返回值從startingTicks,當(dāng)我重置計(jì)時(shí)器時(shí),我只需再次調(diào)用函數(shù)并將startingTick分配給它。不幸的是,從我看到的代碼來看,它并不像調(diào)用QueryPerformanceCounter(),我不知道我應(yīng)該通過什么作為它的論點(diǎn)。
3 回答

慕哥9229398
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
/** 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

紅顏莎娜
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
HRTimer
GetTicks()
HRTimer
- 3 回答
- 0 關(guān)注
- 1172 瀏覽
添加回答
舉報(bào)
0/150
提交
取消