Besides my head exploding this is what happened.
I wanted to measure the execution time of a method from a class. The method was too fast to get an accurate time using QueryPerformanceCounter, GetTickCount or Clock.
I called the method 2000 times and measured the time elapsed.
start=clock();
for (i=0;i<2000;i++)
{
myObject->myMethod(x);
}
end = clock()-start;
printf("->Partial time: %d\n", end);
I was getting an elapsed time of 1.1-1.3 seconds.
I made the code into a function.
void testingFunction(MyObject *myObject,int NumberOfRepetitions, int startAt,int endAt)
{
int i,j;
clock_t start,end;
for (j=0;j<numberOfRepetitions;j++)
{
start=clock();
for (i=startAt;i<endAt;i++)
{
myObject->myMethod(i);
}
end = clock()-start;
printf("->Partial time: %d\n", end);
}
}
When calling the function
for(i=0;i<10;i++)
testingFunction(myObject,1,0,2000);// got time between 1.1-1.3 all 10 times
If calling
testingFunction(myObject,10,0,2000);
the time increased:
Partial time: 1260
Partial time: 1890
Partial time: 2530
Partial time: 3700
Partial time: 4100
Partial time: 5360
etc
I can't understand why this is happenining.