delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/01/08/13:30:51

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <BAY113-DAV35E3128C323B5B930C496F5480@phx.gbl>
X-Sender: captain_webber AT hotmail DOT com
From: "Mr Webber" <captain_webber AT hotmail DOT com>
To: <cygwin AT cygwin DOT com>
References: <4783B96D DOT 9060709 AT huarp DOT harvard DOT edu>
Subject: RE: Does clock() work?
Date: Tue, 8 Jan 2008 13:30:04 -0500
Message-ID: <D5CB0E1DD6C543DE88B9C48EDE1642BF@windows.tecforth.com>
MIME-Version: 1.0
X-Mailer: Microsoft Office Outlook 11
In-Reply-To: <4783B96D.9060709@huarp.harvard.edu>
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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

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 AT cygwin DOT com [mailto:cygwin-owner AT cygwin DOT com] On Behalf Of
Norton Allen
Sent: Tuesday, January 08, 2008 12:57 PM
To: cygwin AT cygwin DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019