Function overhead...
Displaying 1-6 of 6 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Omni

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?

Posted on 2005-01-02 11:06:54 (last edited on 2005-01-02 11:08:05)

Beni

I don't know. I tried it and didn't get the same results as you. Hey, that isn't the actual fillscreen function you use is it?

Posted on 2005-01-04 07:45:52

anonymous

It was the one I used for the demonstration, yes.

Posted on 2005-01-04 09:59:29

anonymous

That's me. Also, it was on a Pentium M 1.5Ghz, so I bet there's a difference between processors, but I wonder about how per-pixel function is faster than per-pixel unwrapped. You didn't have that problem?

--Omni

Posted on 2005-01-04 10:00:36

zonker6666

I was amazed to get the same result - the unwrapped fill screen took longer - not by much but still.
The only thing that springs to mind would be the extra
assignment operation y=0; that needs to be called after the unwrapped version.

Posted on 2005-01-07 13:09:36

Omni

It's just...weird. This shouldn't be happening. Either way, looped or functioned, there's still a variable being initialized, and there shouldn't be a noticeable difference between int y; and y = 0; anyway. I don't know why the timings turn out this way, but I would like to.

Posted on 2005-01-07 17:17:45


Displaying 1-6 of 6 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.