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]

RE: Does clock() work?


CLOCKS_PER_SEC is a machine dependent macro, but not so machine dependent to
recognize that my 32-bit windows box has dual processors.  Not useful for
benchmarking, is it.

clock is not the way to go. It is a crude estimation of processor time.  On
regular UNIX times(2) is the function to use -- cygwin does not seem to have
it.

 I don't know if this helps, but:

My cygwin reports
$ ./chktime
CLOCKS_PER_SEC = 1000
clock() = 31
clock() = 31
clock() = 31
clock() = 31
clock() = 31
clock() = 31
clock() = 31
clock() = 31

My 64-bit Fedora/Linux reports
# ./chktime
CLOCKS_PER_SEC = 1000000
clock() = 0
clock() = 0
clock() = 0
clock() = 0
clock() = 0
clock() = 0
clock() = 0
clock() = 0

-----Original Message-----
From: cygwin-owner@cygwin.com [mailto:cygwin-owner@cygwin.com] On Behalf Of
Norton Allen
Sent: Tuesday, January 08, 2008 12:57 PM
To: cygwin@cygwin.com
Subject: 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/



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