delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/07/03/13:39:00

Sender: nate AT cartsys DOT com
Message-ID: <377E4A2D.F023FABE@cartsys.com>
Date: Sat, 03 Jul 1999 10:36:45 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
X-Mailer: Mozilla 4.08 [en] (X11; I; Linux 2.2.10 i586)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Timing
References: <377CC7E6 DOT EB82B079 AT hotmail DOT com>
Reply-To: djgpp AT delorie DOT com

Young Fan wrote:
> 
> Hi,
> 
> Would someone know how to use setitimer() and getitimer()? I need to
> time how long it takes (to microsecond accuracy if possible, but at
> least millisecond accuracy) to go through a certain for-loop.
> 
> Here's what's in include\sys\time.h:
> 
> struct itimerval {
>   struct  timeval it_interval;    /* timer interval */
>   struct  timeval it_value;       /* current value */
> };
> int getitimer(int _which, struct itimerval *_value);
> int setitimer(int _which, struct itimerval *_value, struct itimerval
> *_ovalue);
> 
> What is _which and what am I supposed to put there?
> 
> I basically need to measure the elapsed time during part of the program,
> without actually pausing program execution like sleep() does.

Then you don't want itimers.  These are more like countdown timers-- you
specify a time and after it elapses a signal is raised.  (_which exists
because there are (I think) two independent timers available.)

You probably want something more like `clock', though it's only accurate
to 55 ms.  There is `uclock', which is accurate to about 1 us, but
apparently it has problems if you're using Windows.  There is also the
CPU's timestamp counter, if you have a Pentium or K5 or better-- it's
accurate to within one clock of your CPU (between 2 and 10 ns depending
on the CPU speed).  Ask me if you want more info on this.
-- 

Nate Eldredge
nate AT cartsys DOT com

- Raw text -


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