Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <3C507C76.7F039537@lapo.it> Date: Thu, 24 Jan 2002 22:28:22 +0100 From: Lapo Luchini X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: it,en,fr,es,ja MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: gettimeofday() does not returns usec resolution References: <002d01c1a511$ed628b50$0fa807d5 AT BRAMSCHE> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit > > I adapted the code to find exactly the minimum time slice, and not "how well > > 1ms of retard is seen" (it was a 0ns or 15000ns, this is always 15000ns; > > moreover printf is out of the "timing" section): > isn't the time slice about 10ms. ? Actually is between 15 and 16ms: try 1: 437687512 - 437703512 = 16000 try 2: 437703512 - 437719512 = 16000 try 3: 437719512 - 437734512 = 15000 try 4: 437734512 - 437750512 = 16000 try 5: 437750512 - 437766512 = 16000 try 6: 437766512 - 437781512 = 15000 try 7: 437781512 - 437797512 = 16000 try 8: 437797512 - 437812512 = 15000 try 9: 437812512 - 437828512 = 16000 try 10: 437828512 - 437844512 = 16000 try 11: 437844512 - 437859512 = 15000 try 12: 437859512 - 437875512 = 16000 try 13: 437875512 - 437891512 = 16000 try 14: 437891512 - 437906512 = 15000 try 15: 437906512 - 437922512 = 16000 try 16: 437922512 - 437937512 = 15000 try 17: 437937512 - 437953512 = 16000 try 18: 437953512 - 437969512 = 16000 try 19: 437969512 - 437984512 = 15000 try 20: 437984512 - 438000512 = 16000 Just try this source: #include #define TV2LONG(t) ((unsigned long)t.tv_sec)*1000000+((unsigned long)t.tv_usec) int main() { struct timeval tp; unsigned long a, b; unsigned int n = 1; for(n=1; n<=20; n++) { gettimeofday(&tp, 0); a = TV2LONG(tp); do { gettimeofday(&tp, 0); } while((b = TV2LONG(tp)) <= a); printf("try %2d: %ld - %ld = %ld\n", n, a, b, b-a); } gettimeofday(&tp, 0); a = TV2LONG(tp); usleep(1000000); gettimeofday(&tp, 0); b = TV2LONG(tp); printf("sleep: %ld - %ld = %ld usec\n", a, b, b-a); } -- Lapo 'Raist' Luchini lapo AT lapo DOT it (PGP & X.509 keys available) http://www.lapo.it (ICQ UIN: 529796) -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/