delorie.com/archives/browse.cgi | search |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sources.redhat.com/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
X-Injected-Via-Gmane: | http://gmane.org/ |
To: | cygwin AT cygwin DOT com |
From: | "Alex Vinokur" <alexvn AT connect DOT to> |
Subject: | struct timeval : accuracy of tv_usec |
Date: | Mon, 28 Apr 2003 07:48:00 +0300 |
Lines: | 125 |
Message-ID: | <b8ibo1$btm$1@main.gmane.org> |
X-Complaints-To: | usenet AT main DOT gmane DOT org |
X-MSMail-Priority: | Normal |
X-Newsreader: | Microsoft Outlook Express 5.50.4522.1200 |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.50.4522.1200 |
=========================================== Windows 2000 CYGWIN_NT-5.0 1.3.22(0.78/3/2) GNU gcc version 3.2-3 20020927 (prerelease) =========================================== <QUOTE from http://www.gnu.org/manual/glibc-2.2.5/html_node/Elapsed-Time.html > struct timeval Data Type The struct timeval structure represents an elapsed time. It is declared in sys/time.h and has the following members: long int tv_sec This represents the number of whole seconds of elapsed time. long int tv_usec This is the rest of the elapsed time (a fraction of a second), represented as the number of microseconds. It is always less than one million. </QUOTE> Here is some program and results of its run. Is 'accuracy of tv_usec' is microseconds here ? We can see the almost 2000 prints have the same tv_usec value. ========= C code : BEGIN ========= /* File t.c */ #include <stdio.h> #include <sys/resource.h> #include <assert.h> int main() { #define TOTAL_TIMES 7500 int i; struct rusage tval; for (i = 0; i < TOTAL_TIMES; i++) { getrusage(RUSAGE_SELF, &tval); printf ("[%d] getrusage = %ld.%ld\n", i, tval.ru_utime.tv_sec, tval.ru_utime.tv_usec ); fflush(stdout); assert (tval.ru_utime.tv_sec >= 0); assert (tval.ru_utime.tv_usec >= 0); } return 0; } ========= C code : END =========== ========= Compiling & Running : BEGIN ========= % gcc t.c % a > out % cat out [0] getrusage = 0.10000 [1] getrusage = 0.10000 [snip] [1979] getrusage = 0.10000 [1980] getrusage = 0.10000 [1981] getrusage = 0.20000 [1982] getrusage = 0.20000 [4081] getrusage = 0.20000 [snip] [4082] getrusage = 0.20000 [4083] getrusage = 0.30000 [4084] getrusage = 0.30000 [4085] getrusage = 0.30000 [snip] [5719] getrusage = 0.30000 [5720] getrusage = 0.30000 [5721] getrusage = 0.40000 [5722] getrusage = 0.40000 [snip] [6512] getrusage = 0.40000 [6513] getrusage = 0.40000 [6514] getrusage = 0.50000 [6515] getrusage = 0.50000 [snip] [7309] getrusage = 0.50000 [7310] getrusage = 0.50000 [7311] getrusage = 0.60000 [7312] getrusage = 0.60000 [snip] [7498] getrusage = 0.60000 [7499] getrusage = 0.60000 ========= Compiling & Running : END =========== -- ========================================== Alex Vinokur mailto:alexvn AT connect DOT to http://www.simtel.net/pub/oth/19088.html http://sourceforge.net/users/alexvn ========================================== -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |