View Single Post
Re: need your advice on clock()
Old
  (#4)
botmeister
Ex-Council Member
 
botmeister's Avatar
 
Status: Offline
Posts: 1,090
Join Date: Nov 2003
Location: Canada
Default Re: need your advice on clock() - 13-01-2004

oops, you are right, the code I posted won't work for at least 2 or 3 different reasons 8o

Let's have a look at this one instead

static float time_in_seconds = 0;
static long prev_clock = 0;
long current_clock;
float time_diff;


current_clock = clock();

if (current_clock < prev_clock)
{

// calculate ticks elapsed up to rollover event
time_diff = LONG_MAX - prev_clock;

// add on ticks elapsed after rollover event
time_diff = time_diff + current_clock + 1;
}
else

time_diff = current_clock - prev_clock;

prev_clock = current_clock;
time_in_seconds += time_diff / CLOCKS_PER_SEC;
return time_in_seconds
Note
The function MUST be called at least once between every rollover event!

DAMN! I still have no idea how to copy/paste code into this thing so it shows up the way I want it to. I need a tutorial or something.


Maker of the (mEAn) Bot.Admin Manager

"In theory, there is no difference between theory and practice. But, in practice, there is." - Jan L.A. van de Snepscheut

Last edited by botmeister; 13-01-2004 at 05:12..
  
Reply With Quote