delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/03/12/09:01:27

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
Message-ID: <3C8DC2DA.230B4309@acm.org>
From: Eric Sosman <esosman AT acm DOT org>
X-Mailer: Mozilla 4.72 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: timing routines (repost)...
References: <20020311142313 DOT 11973 DOT qmail AT mellon DOT com>
Lines: 29
Date: Tue, 12 Mar 2002 13:55:00 GMT
NNTP-Posting-Host: 12.91.0.18
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc05-news.ops.worldnet.att.net 1015941300 12.91.0.18 (Tue, 12 Mar 2002 13:55:00 GMT)
NNTP-Posting-Date: Tue, 12 Mar 2002 13:55:00 GMT
Organization: AT&T Worldnet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Brozewicz Robert F wrote:
>
> can someone please share with me a 'c' routine that can be used to display
> how long a program executes in hours/minutes/second and down to the lowest
> time possible.

    Everything you need is in the <time.h> header.

    To measure elapsed time, call the time() function before and after
the
activity of interest and use difftime() to calculate the interval in
seconds.

    To measure CPU time, call the clock() function before and after the
activity, subtract the earlier value from the later, and divide by the
constant CLOCKS_PER_SEC to convert the result to seconds.  Consult
"info"
for some limitations on the length of interval you can measure this way.

    DJGPP provides some finer-grained clocks in addition to these two
Standard C approaches, but for durations in the "hours/minutes/second"
class the additional precision is probably noise.  Again, see "info."

    If what you're really interested in is seeing which parts of your
program use the most time, look up "gprof" in "info" and in the FAQ.

-- 
Eric Sosman
esosman AT acm DOT org

- Raw text -


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