Exetools  

Go Back   Exetools > General > General Discussion

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2010, 19:32
Git's Avatar
Git Git is offline
Old Git
 
Join Date: Mar 2002
Location: Torino
Posts: 1,116
Rept. Given: 220
Rept. Rcvd 265 Times in 157 Posts
Thanks Given: 110
Thanks Rcvd at 220 Times in 126 Posts
Git Reputation: 200-299 Git Reputation: 200-299 Git Reputation: 200-299
I see your point overflow, but thinking about it, couldn't the GetTickCount() function get robbed of CPU time and hence run slow?. All depends how it is implemented. If it reads a real time clock, or is interrupt driven then it should never return a low count. If it is just a queued task bumping a counter I think it could. In this example, the same applies to the Sleep() function.

Git
Reply With Quote
The Following User Gave Reputation+1 to Git For This Useful Post:
oVERfLOW (09-04-2010)
  #2  
Old 09-04-2010, 18:12
gigaman gigaman is offline
Friend
 
Join Date: Jun 2002
Posts: 87
Rept. Given: 0
Rept. Rcvd 3 Times in 2 Posts
Thanks Given: 0
Thanks Rcvd at 14 Times in 11 Posts
gigaman Reputation: 4
You cannot rely on any exact timing on Windows - it's not a real-time OS.
A context switch may always occur in the middle of your code, delaying it significantly. For example, you call the first GetTickCount, then Sleep - and after the Sleep function returns (and before the second GetTickCount is called), your process loses the CPU, another running process uses it for a while (say 20ms to the next timeslice), and then you get it back - so it looks like your Sleep actually took 20ms longer.
[OK, I know this scenario is quite unlikely with this particular code, because you'd probably get a full timeslice after Sleep, but it's just to illustrate the point].

As for why it should be less than 1000 ms... even the today's hardware doesn't make it easy for exact timing. With all those turbo modes (the CPU frequency gets temporarily increased under load) and power saving features (the CPU clock is reduced if not under heavy load - especially on mobile devices), it's very hard to measure time exactly.

VirtualDub's author wrote about it years ago: http://virtualdub.org/blog/pivot/entry.php?id=106
Reply With Quote
The Following User Gave Reputation+1 to gigaman For This Useful Post:
oVERfLOW (09-06-2010)
  #3  
Old 09-04-2010, 18:26
Squidge's Avatar
Squidge Squidge is offline
Drunken Squirrel
 
Join Date: Oct 2002
Posts: 412
Rept. Given: 4
Rept. Rcvd 9 Times in 4 Posts
Thanks Given: 0
Thanks Rcvd at 6 Times in 6 Posts
Squidge Reputation: 9
It could also be that the resolution of the system clock isn't that accurate.

Did you try using timeBeginPeriod to set the timer resolution ?

Don't forget that Sleep works by creating a thread to release the remainder of your time slice, which also involves delays.
Reply With Quote
Reply

Tags
sleep, time

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



All times are GMT +8. The time now is 19:57.


Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX, chessgod101
( Since 1998 )