Click here to Skip to main content
13,350,289 members (45,505 online)

C / C++ / MFC

 
GeneralMessage Closed Pin
14-Mar-13 19:53
memberRobert Inventor14-Mar-13 19:53 
GeneralMessage Closed Pin
14-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 
QuestionJSON Parser Pin
john56327-Mar-13 0:20
memberjohn56327-Mar-13 0:20 
AnswerRe: JSON Parser Pin
CPallini7-Mar-13 1:17
mvpCPallini7-Mar-13 1:17 
QuestionRe: JSON Parser Pin
DavidCrow7-Mar-13 4:00
memberDavidCrow7-Mar-13 4:00 
QuestionWin32_NetworkAdapter class to change network configuration Pin
toms from newdelhi3-Mar-13 21:22
membertoms from newdelhi3-Mar-13 21:22 
AnswerRe: Win32_NetworkAdapter class to change network configuration Pin
DavidCrow4-Mar-13 4:23
memberDavidCrow4-Mar-13 4:23 
GeneralRe: Win32_NetworkAdapter class to change network configuration Pin
toms from newdelhi4-Mar-13 17:36
membertoms from newdelhi4-Mar-13 17:36 
QuestionLooking for good example for CMFCPropertyGridCtrl . Pin
oleg631-Mar-13 7:14
memberoleg631-Mar-13 7:14 
AnswerRe: Looking for good example for CMFCPropertyGridCtrl . Pin
«_Superman_»1-Mar-13 17:31
member«_Superman_»1-Mar-13 17:31 
QuestionLinker error with CLSID defined in uuids.h Pin
Vaclav_Sal27-Feb-13 6:56
memberVaclav_Sal27-Feb-13 6:56 
AnswerRe: Linker error with CLSID defined in uuids.h Pin
Richard MacCutchan27-Feb-13 7:19
mvpRichard MacCutchan27-Feb-13 7:19 
GeneralRe: Linker error with CLSID defined in uuids.h Pin
Vaclav_Sal27-Feb-13 7:38
memberVaclav_Sal27-Feb-13 7:38 

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 |
Web01 | 2.8.180111.1 | Last Updated 19 Jan 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid