This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

struct timeval : accuracy of tv_usec


===========================================
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]