I am trying to calculate the delta in milliseconds with something like this:
int olddelta = 0;
int delta = 0;
const clock_t begin_time = clock();
while (true) {
olddelta=delta;
delta=clock()-olddelta;
cout<<delta<<endl;
}
however this is not working as the delta is definitely not over 4000, and it seems to get progressively higher. What have i done incorrectly?
Since you are using
clock()
, you need to divide it byCLOCKS_PER_SEC
to obtain the result expressed in seconds. To get fractions, castclock()
todouble
before the division:If you want to measure the time of a single iteration, change the loop as follows: