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
|