Click here to Skip to main content
12,635,246 members (23,752 online)

C / C++ / MFC

 
GeneralMessage Removed Pin
Robert Inventor14-Mar-13 19:53
memberRobert Inventor14-Mar-13 19:53 
GeneralMessage Removed Pin
Robert Inventor14-Mar-13 20:19
memberRobert Inventor14-Mar-13 20:19 
AnswerRe: timeGetTime() is unreliable on my computer too, not monotonic! Pin
Robert Inventor19-Mar-13 8:31
memberRobert Inventor19-Mar-13 8:31 
QuestionQueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor14-Mar-13 16:50
memberRobert Inventor14-Mar-13 16:50 
AnswerRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor14-Mar-13 19:07
memberRobert Inventor14-Mar-13 19:07 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex15-Mar-13 1:24
memberdusty_dex15-Mar-13 1:24 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor18-Mar-13 15:44
memberRobert Inventor18-Mar-13 15:44 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex18-Mar-13 23:08
memberdusty_dex18-Mar-13 23: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 Pin
Robert Inventor19-Mar-13 7:19
memberRobert Inventor19-Mar-13 7:19 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex19-Mar-13 9:34
memberdusty_dex19-Mar-13 9:34 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor20-Mar-13 11:10
memberRobert Inventor20-Mar-13 11:10 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor20-Mar-13 12:12
memberRobert Inventor20-Mar-13 12:12 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
dusty_dex20-Mar-13 12:18
memberdusty_dex20-Mar-13 12:18 
GeneralRe: QueryPerformanceCounter inaccurate timing even with use of SetThreadAffinityMask Pin
Robert Inventor20-Mar-13 13:15
memberRobert Inventor20-Mar-13 13:15 
QuestionHelp in Win32 programming with c++ Pin
naseer86114-Mar-13 9:44
membernaseer86114-Mar-13 9:44 
AnswerRe: Help in Win32 programming with c++ Pin
ThePhantomUpvoter14-Mar-13 9:50
memberThePhantomUpvoter14-Mar-13 9:50 
GeneralRe: Help in Win32 programming with c++ Pin
naseer86118-Mar-13 10:41
membernaseer86118-Mar-13 10:41 
AnswerRe: Help in Win32 programming with c++ Pin
Maximilien14-Mar-13 9:54
memberMaximilien14-Mar-13 9:54 
AnswerRe: Help in Win32 programming with c++ Pin
Pravinda Amarathunge16-Mar-13 3:55
memberPravinda Amarathunge16-Mar-13 3:55 
QuestionNeed a free image library, png, Visual Studio 6.0 Pin
Andrlage14-Mar-13 6:52
memberAndrlage14-Mar-13 6:52 
AnswerRe: Need a free image library, png, Visual Studio 6.0 Pin
Richard MacCutchan14-Mar-13 7:22
mvpRichard MacCutchan14-Mar-13 7:22 
AnswerRe: Need a free image library, png, Visual Studio 6.0 Pin
Flaviu214-Mar-13 22:19
memberFlaviu214-Mar-13 22:19 
QuestionMSCOWRKS.DLL ? Pin
ForNow13-Mar-13 4:10
memberForNow13-Mar-13 4:10 
AnswerRe: MSCOWRKS.DLL ? Pin
Richard MacCutchan13-Mar-13 4:53
mvpRichard MacCutchan13-Mar-13 4:53 
GeneralRe: MSCOWRKS.DLL ? Pin
ForNow13-Mar-13 5:12
memberForNow13-Mar-13 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.161208.2 | Last Updated 10 Dec 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid