Click here to Skip to main content
       

C / C++ / MFC

 
GeneralMessage Removed PinmemberRobert Inventor14-Mar-13 18:53 
GeneralMessage Removed PinmemberRobert Inventor14-Mar-13 19:19 
AnswerRe: timeGetTime() is unreliable on my computer too, not monotonic! PinmemberRobert Inventor19-Mar-13 7:31 
QuestionQueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor14-Mar-13 15:50 
AnswerRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor14-Mar-13 18:07 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pinmemberdusty_dex15-Mar-13 0:24 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor18-Mar-13 14:44 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask [modified] Pinmemberdusty_dex18-Mar-13 22:08 
If you're seeing 15ms then I'm pretty sure that's the thread 'quantum' of Windows scheduling. It used to be 10ms on Windows NT 4.0
 
I've encountered this problem too. The best you can do is to not bother with the high perf counters, as they're still at the mercy of scheduler. All I do is get the average of about 3-5 readings, but the trick seems to be to put the thread to sleep until the next exact second (1000-current_millisecond) and repeat with timing durations less than the scheduling quantum. Which means it will take 3 - 4 seconds to get your average. Put thread into realtime priority, which should reduce preemption. (if you're confident that your timing-code is free of bugs)
 
sleep until msec:000, timing loop < 15ms
 
repeat as many times as you need to, the cpu scaling of some processors creates problems with initial result, so be prepared to discard the first and second result or ramp up the cpu to 100%.
 
If it's any consolation it's the same problem with any pre-emptive OS, but also disappointing to know that xGHz machines can't give you a reliable reading from within a modern OS. Linux calculates the timing before it boots.
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
 
That's what machines are for.
 
Got a problem?
Sleep on it.


modified 19-Mar-13 7:12am.

AnswerRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor19-Mar-13 6:19 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pinmemberdusty_dex19-Mar-13 8:34 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor20-Mar-13 10:10 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor20-Mar-13 11:12 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pinmemberdusty_dex20-Mar-13 11:18 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask PinmemberRobert Inventor20-Mar-13 12:15 
QuestionHelp in Win32 programming with c++ Pinmembernaseer86114-Mar-13 8:44 
AnswerRe: Help in Win32 programming with c++ PinmemberThePhantomUpvoter14-Mar-13 8:50 
GeneralRe: Help in Win32 programming with c++ Pinmembernaseer86118-Mar-13 9:41 
AnswerRe: Help in Win32 programming with c++ PinmemberMaximilien14-Mar-13 8:54 
AnswerRe: Help in Win32 programming with c++ PinmemberPravinda Amarathunge16-Mar-13 2:55 
QuestionNeed a free image library, png, Visual Studio 6.0 PinmemberAndrlage14-Mar-13 5:52 
AnswerRe: Need a free image library, png, Visual Studio 6.0 PinmvpRichard MacCutchan14-Mar-13 6:22 
AnswerRe: Need a free image library, png, Visual Studio 6.0 PinmemberFlaviu214-Mar-13 21:19 
QuestionMSCOWRKS.DLL ? PinmemberForNow13-Mar-13 3:10 
AnswerRe: MSCOWRKS.DLL ? PinmvpRichard MacCutchan13-Mar-13 3:53 
GeneralRe: MSCOWRKS.DLL ? PinmemberForNow13-Mar-13 4:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 20 Aug 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid