Here's the code.
void MathFunc()
{
int a;
a = 0;
a = a + 1;
a = a * 10;
a = a / 10;
a = a % 10;
}
void GfxFunc_FillScreen(int color)
{
int x, y;
while (y < ImageHeight(screen))
{
x = 0;
while (x < ImageWidth(screen))
{
SetPixel(x, y, color, screen);
x++;
}
y++;
}
}
Here's the deal. I basically loop these functions 2000000 times, or two million.
I then unwrap the function and insert the actual code into the loop. For example.
void autoexec()
{
int c;
while (c < 2000000)
{
MathFunc();
c++;
}
}
void autoexec()
{
int c, a;
while (c < 2000000)
{
a = 0;
a = a + 1;
a = a * 10;
a = a / 10;
a = a % 10;
c++;
}
}
Finally, I track how long the loop takes for each piece of code, in a function and unwrapped.
MathFunc() called: 4004 centisecs
MathFunc() unwrapped: 3275 centisecs
FillScreen() called: 7364 centisecs
FillScreen() unwrapped: 7747 centisecs
(note I only looped the FillScreen code for 200 times. Otherwise I would have been here all day.)
...I understand the overhead difference with the math function, but why is the FillScreen code faster IN a function call?