delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/02/02/03:04:46

Delivered-To: listarch-cygwin AT sourceware DOT cygnus DOT com
Conversion: Allowed
Original-Encoded-Information-Types: IA5-Text
Disclose-Recipients: Prohibited
Alternate-Recipient: Allowed
Message-Id: <0240136B5C1E101A*/c=us/admd=0/prmd=aero/o=notes/s=Kasper/g=Brian/i=P/@MHS>
Date: Mon, 1 Feb 1999 07:01:53 -0800
From: Brian P Kasper <Brian DOT P DOT Kasper AT notes DOT aero DOT org>
To: gnu-win32 AT cygnus DOT com
Subject: Re: B20.1 clock() function bug?
Sender: owner-gnu-win32 AT cygnus DOT com

><<   The clock function's era begins (with a value of 0) when the
>   C program starts to execute.>>
>
>I don't think you can count on that.  It should return a value of type
>clock_t, which overflows and starts over periodically.

I don't think the above quote says anything about the return value
overflowing, just that it starts at 0 when the program begins
execution.

This makes sense, as when I checked K&R (as you suggested below,
oops, shoulda done that first off), clock() is defined as

"clock returns the processor time used by the program since the
beginning of execution, or -1 if unavailable.  clock()/CLK_TCK
is a time in seconds."

So, clock() should in fact return a *processor* time, not an
absolute time.  Microsoft may have implemented it differently
(no surprise there).

><<   It returns times measured in 1/CLOCKS_PER_SEC (which
>   equals 1/1000 for Microsoft C).>>
>
>Always use the local CLOCK_T.  Who knows when it might change or when you
>might use a different brand of software.

Yeah, I know -- I am using the #defined value.  The goal here
*is* software portability.  I'm just surprised that I'm getting
different results on the same OS with 2 different compilers.

><< Am I misinterpreting the behavior of clock()?  Does it return
> user time instead of absolute system time? >>
>
>Read your C textbook.  That's what it should do, at least on NT.  On W95, 
this

Did that.  Should have done that earlier.

Thanks for the response.  I'm going to investigate compiler-independent
timing.

-Brian
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


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