delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/02/02/12:48:02

Delivered-To: listarch-cygwin AT sourceware DOT cygnus DOT com
Message-Id: <199902011955.LAA28882@aleph.ssd.hal.com>
Subject: Re: B20.1 clock() function bug?
To: Brian DOT P DOT Kasper AT notes DOT aero DOT org (Brian P Kasper)
Date: Mon, 1 Feb 1999 11:55:38 -0800 (PST)
Cc: gnu-win32 AT cygnus DOT com
In-Reply-To: <040C736B1E5D205D*/c=us/admd=0/prmd=aero/o=notes/s=Kasper/g=Brian/i=P/@MHS> from "Brian P Kasper" at Jan 29, 99 08:46:10 am
From: "J. J. Farrell" <jjf AT bcs DOT org DOT uk>
X-Mailer: ELM [version 2.4 PL23]
Sender: owner-gnu-win32 AT cygnus DOT com

> From: Brian P Kasper <Brian DOT P DOT Kasper AT notes DOT aero DOT org>
> 
> I'm getting different answers from the clock() function
> under Cygwin B20.1 and Microsoft Visual C++ 6.0.
> 
> I'm using the clock() function and the CLOCKS_PER_SEC
> #define to time the execution of some code.  I'm also comparing
> the run time with the real world using a stopwatch.
> 
> If I run the program for 10 seconds by my stopwatch, the Visual C++
> version of the code reports that 10 seconds have passed.  If I
> run the Cygwin version for 10 seconds, the program reports that
> only 6 seconds have passed.
> 
> My understanding is that clock() reports the number of system
> clock ticks which have passed since the program started executing.
> According to the the VC++ documentation,
> 
>   The clock function,s era begins (with a value of 0) when the
>   C program starts to execute.
>   It returns times measured in 1/CLOCKS_PER_SEC (which
>   equals 1/1000 for Microsoft C).

clock() is a Standard C function defined as returning

  the implementation's best approximation to the processor time
  used by the program since the beginning of an implementation-
  defined era related only to the program invocation.

The term "processor time used" is not defined, and I guess that
VC++ and Cygwin are interpreting it differently. It looks like
Cygwin's interpretation is closer to the traditional UNIX one. I
don't see how you could reasonably equate elapsed time to processor
time on a multi-tasking OS, so I'd say the VC++ version is buggy
- or at least that it's "best" isn't very good.

Dividing by CLOCKS_PER_SEC is the correct way to convert it to
seconds.


-
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