[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: time tutorial
Erik wrote:
>
> -Erik <erik@smluc.org> [http://math.smsu.edu/~br0ke]
>
> The opinions expressed by me are not necessarily opinions. In all
> probability, they are random rambling, and to be ignored. Failure to ignore
> may result in severe boredom or confusion. Shake well before opening. Keep
> Refrigerated.
>
Your wish is an order,
First to avoid zero times or infinite results, scale your results and
add
a call counter to the result.
static clock_t last_clock;
static int clock_counter;
int new_clock;
new_clock=clock();
if ( new_clock == last_clock ) {
return last_clock*100 + clock_counter ++;
}
clock_counter=0;
last_lock=new_clock;
return last_clock*100;
Second you forget the "tsc" (time stamp counter) register, which is
available atleast
on any ">=586" and alphas.
This gives you the exact time, no overhead (task-switches, calls, ...),
here is the code:
/**
** Read the tsc (time-stamp counter) register of the processor.
**
** @return the rtc register
*/
static __inline u_int64_t rdtsc(void)
{
#ifdef __i386__
u_int64_t rv;
__asm __volatile(".byte 0x0f, 0x31" : "=A" (rv));
#endif
#ifdef __alpha__
int rv;
__asm __volatile("rpcc %0" : "=r" (rv));
#endif
return rv;
}
Johns
-------------------------------------------------------------------------
ALE Clone: Free W*rCr*ft II source: http://yi.org/johns