Mail Archives: djgpp/1999/07/03/13:39:00
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 -