X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org X-YMail-OSG: QqOf2P0VM1le1VcaNlJw68AfQpoZEq5xdT74uDAFDmOGQBNFSq5NZckIJ6g6Grovg9s7JTITLFNx.mS2SrVSEFjW7bO0pWSRLk0gpdgfCg2iTJYF9n5xmIEuXSy0Aj6gC99nEZA- Message-ID: <4783C3D9.6020303@sbcglobal.net> Date: Tue, 08 Jan 2008 18:41:29 +0000 From: Greg Chicares User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: Does clock() work? References: <4783B96D DOT 9060709 AT huarp DOT harvard DOT edu> In-Reply-To: <4783B96D.9060709@huarp.harvard.edu> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com On 2008-01-08 17:57Z, Norton Allen wrote: [snip code that times this inner loop:] > > for ( i = 0; i < 8; i++ ) { > sleep(1); > cur_time = clock(); > printf( "clock() = %ld\n", cur_time ); > > 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.) I get similar results with the same program. According to C99 7.23.2.1/2, "The clock function determines the processor time used." so I'd guess that sleep() is consuming only wall-clock time. Here's your program with an inner loop that consumes cycles: /tmp[0]$cat clock_test.c #include #include #include #include int main( int argc, char **argv ) { clock_t cur_time, cps = CLOCKS_PER_SEC; int i, j; volatile unsigned int v; printf( "CLOCKS_PER_SEC = %ld\n", cps ); for ( i = 0; i < 8; i++ ) { for ( j = 0; j < INT_MAX / 10; j++ ) { v++; } cur_time = clock(); printf( "clock() = %ld\n", cur_time ); } return 0; } /tmp[0]$gcc -o clock_test.exe clock_test.c /tmp[0]$./clock_test CLOCKS_PER_SEC = 1000 clock() = 437 clock() = 859 clock() = 1265 clock() = 1687 clock() = 2093 clock() = 2515 clock() = 2937 clock() = 3343 -- 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/