Thread: timing issue
View Single Post
  #3 (permalink)  
Old September 22nd, 2004, 07:10 AM
rikelme rikelme is offline
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to rikelme
Default

Hi,

There is a function:
clock_t clock(void);
in <time.h> which eturns number of clock ticks since process start, and there si a macro called CLK_TCK who defines the relation betwen clock tick and second (clock ticks per second).
So, if you want to calculate time elapsed betwen two events:


float timeElapsed;
clock_t clock0, clock1;
//event 1 happend:
clock0 = clock();
//time is running....
//event 2 happend:
clock1 = clock();
//time elapsed in seconds:
timeElapsed = (clock1 - clock0)/CLK_TCK;
/*just devide it with 1.000 to get it in miliseconds or
with 1.000.000 to get it in microseconds */

Try it, I think it will work :)


Miroslav Ristic
Reply With Quote