This is the mail archive of the cygwin@sourceware.cygnus.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]

Re: Clock() bug on B19


On 24 Apr 98 at 17:47, Tein Horng Yuan wrote:

> Hi,
> 
> I am running gnu-win32 B19-1 on a PII-233 system.  Because I need to
> measure
> the CPU time, I find out 'clock' is not function correct.  A test
> program is attached.
> Please send me email to tyuan@beta.wsl.sinica.edu.tw
> 
> By the way, will you have Pentium II optimization version of gcc?
> Thanks.
> 
> -- Tein

Hello, 

please use the GetTickCount() function of the Win32 API.  It returns
the number of milliseconds that have elapsed since Windows was
started.  I changed your program a little to include this
modification as well as eliminate gcc -Wall warnings.

Hope it is helpful,
--Hilton

---------------------------------------------------------------------
#include <windows.h> /* GetTickCount() */

#include <stdio.h>
#include <math.h>

typedef double REAL;

REAL second(void)
{ return ( ((REAL)GetTickCount ()) / ((REAL)1000.0) ); }

int main (void){ /* explicit main return type */
double a,b,c;

// long i,j,k,l,m,n,o,p; /* vars not used should be eliminated */ long
i, k,l;

c= 0;
b= second();
for(i=0; i<1024 * 1024 * 1024; i ++) {

  for(k=0; k<1024  ; k ++)
  for(l=0; l<1024 ; l ++)
    a = sin(l) + cos(k);
 c=b;
 b=second();
// c= c - b;
 c = b - c; // b is later than c 

 printf("%ld, %f, %f\n", i, b, c); /* i is long, use a long format */
 }

 return (0); /* to make gcc -Wall happy */
}




-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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