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

Does clock() work?


I am trying to write a benchmark application, and figured I'd use clock() for sub-second resolution timing, but I got non-sensical results. I check the cygwin archives, but the only mention I saw was that clock() didn't work on Win98. Here's my test code, chktime.c:

   #include <time.h>
   #include <unistd.h>
   #include <stdio.h>

int main( int argc, char **argv ) {
clock_t cur_time, cps = CLOCKS_PER_SEC;
int i;
printf( "CLOCKS_PER_SEC = %ld\n", cps );
for ( i = 0; i < 8; i++ ) {
sleep(1);
cur_time = clock();
printf( "clock() = %ld\n", cur_time );
}
return 0;
}


and here's the output I get:

   Cygwin> ./chktime
   CLOCKS_PER_SEC = 1000
   clock() = 171
   clock() = 171
   clock() = 171
   clock() = 171
   clock() = 171
   clock() = 171
   clock() = 171
   clock() = 171
   Cygwin>

I would expect the clock() values to increase by approximately 1000 on each iteration. (Yes, the sleep() seems to be working, as the lines come out at about 1 Hz.)

Is this a known problem? Do others get this result, or do I have a corrupted library?

-Norton Allen


-- 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]