Hello, i was wondering if i could get an opinion on the following code as it is giving me a headache:
int counter = 498853097;
int k = 0;
clock_t start, end;
float seconds1,seconds2;
start = clock();
for (int i = 0; i < counter; i++)
{
k++;
}
end = clock();
seconds2 = (float)(end - start) / CLOCKS_PER_SEC;
start = clock();
for (int i = 0; i < counter; i++);
end = clock();
seconds1 = (float)(end - start) / CLOCKS_PER_SEC;
printf("\n Time 2 [%f] - Time 1 [%f] = %f",seconds2,seconds1,seconds2-seconds1);
It's the exact same repetition twice, except one of them has an integer increment.
The result i'm getting is negative every time, eg
Time 2 [0.877000] - Time 1 [0.955000] = -0.078000. What am i missing?