delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2008/01/08/12:57:18

X-Recipient: archive-cygwin AT delorie DOT com
X-Spam-Check-By: sourceware.org
Message-ID: <4783B96D.9060709@huarp.harvard.edu>
Date: Tue, 08 Jan 2008 12:57:01 -0500
From: Norton Allen <allen AT huarp DOT harvard DOT edu>
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Does clock() work?
Received-SPF: pass (ent.arp.harvard.edu: 10.0.0.122 is authenticated by a trusted mechanism)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.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

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/

- Raw text -


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