Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > RReeaallyy long function -- inlining?

Reply
Thread Tools

RReeaallyy long function -- inlining?

 
 
Tomás
Guest
Posts: n/a
 
      03-31-2006

The common persuasion is:

Big function -- leave it outline.

Small function -- make it inline.


In code I'm writing at the moment, I have a fairly long function, so it
wouldn't cross my mind to make it inline. However, the function is
invoked only once, and its invokation is at the very beginning of the
program's execution.

Regardless of a function's size, would it not make sense to make it
inline if it's only called once, so that it's code is "expanded in-
place" rather that there being some sort of memory redirection?

Should I stick to the formula of "Big=outline, Small=inline" and simply
rely on the compiler to expand the code in-place if the function is only
invoked once?

-Tomás
 
Reply With Quote
 
 
 
 
Noah Roberts
Guest
Posts: n/a
 
      03-31-2006

Tomás wrote:

> Should I stick to the formula of "Big=outline, Small=inline" and simply
> rely on the compiler to expand the code in-place if the function is only
> invoked once?


May as well. The compiler will do what it does regardless. It doesn't
have to obey the inline keyword. The only thing you will surely
accomplish is to fill a header up with a bunch of code...which will
increase your comile times and source code dependencies surely.

 
Reply With Quote
 
 
 
 
Jakob Bieling
Guest
Posts: n/a
 
      03-31-2006
Tomás <(E-Mail Removed)> wrote:
> The common persuasion is:
>
> Big function -- leave it outline.
>
> Small function -- make it inline.
>
>
> In code I'm writing at the moment, I have a fairly long function, so
> it wouldn't cross my mind to make it inline. However, the function is
> invoked only once, and its invokation is at the very beginning of the
> program's execution.
>
> Regardless of a function's size, would it not make sense to make it
> inline if it's only called once, so that it's code is "expanded in-
> place" rather that there being some sort of memory redirection?
>
> Should I stick to the formula of "Big=outline, Small=inline" and
> simply rely on the compiler to expand the code in-place if the
> function is only invoked once?


If it is only invoked once, why care whether it is inlined or not?
You will never be able to see a difference in performance.

hth
--
jb

(reply address in rot13, unscramble first)


 
Reply With Quote
 
Tomás
Guest
Posts: n/a
 
      03-31-2006

> If it is only invoked once, why care whether it is inlined or not?
> You will never be able to see a difference in performance.


If it's called "outline", then the program counter will be moved.

If it's called "inline", the control will simply flow into the function.

-Tomás
 
Reply With Quote
 
Thomas Tutone
Guest
Posts: n/a
 
      03-31-2006

Tomás wrote:

> > If it is only invoked once, why care whether it is inlined or not?
> > You will never be able to see a difference in performance.

>
> If it's called "outline", then the program counter will be moved.
>
> If it's called "inline", the control will simply flow into the function.


I'm not clear on what your point is. The increased time it takes to
execute a function call - that is, push the current value of the
program counter to the stack, load the program counter with a new
value, and, and at the end of that, popping the saved program counter
back into the stack - rather than simply incrementing the program
counter (if the function is inlined) is on the order of nanoseconds.
To the programmer and the user, what possible benefit could there be
from saving a few nanoseconds?

The rule should be don't inline unless there is compelling reason to do
so. There isn't one here.

Best regards,

Tom

 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      03-31-2006

"Tomas" <(E-Mail Removed)> wrote in message
news:M0eXf.7750$(E-Mail Removed)...
>
>> If it is only invoked once, why care whether it is inlined or not?
>> You will never be able to see a difference in performance.

>
> If it's called "outline", then the program counter will be moved.
>
> If it's called "inline", the control will simply flow into the function.
>
> -Tomas


Are you saying that there's a discernable difference in performance between
making a function call and not making a function call, when it's done ONCE?
What, it'll take a millisecond longer? Forget about it... program for
readability, correctness, and maintainability. Only worry about performance
if you're having a performance problem.

-Howard



 
Reply With Quote
 
Tomás
Guest
Posts: n/a
 
      03-31-2006
Howard posted:

>
> "Tomas" <(E-Mail Removed)> wrote in message
> news:M0eXf.7750$(E-Mail Removed)...
>>
>>> If it is only invoked once, why care whether it is inlined or
>>> not?
>>> You will never be able to see a difference in performance.

>>
>> If it's called "outline", then the program counter will be moved.
>>
>> If it's called "inline", the control will simply flow into the
>> function.
>>
>> -Tomas

>
> Are you saying that there's a discernable difference in performance
> between making a function call and not making a function call, when
> it's done ONCE? What, it'll take a millisecond longer? Forget about
> it... program for readability, correctness, and maintainability. Only
> worry about performance if you're having a performance problem.
>
> -Howard


Yes, but I shouldn't throw performance out the window just because my
code works.

Let's say that it runs a milisecond longer:

Now imagine we're decoding gigabytes of data, and that my "progam" is run
twenty thousand times.

20000 x .001 = 20 seconds


-Tomás
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-31-2006
Tomás wrote:

> The common persuasion is:
>
> Big function -- leave it outline.
>
> Small function -- make it inline.


Inlined opcodes don't automatically make something faster.

The best rule is to out-of-line (or inline) absolutely everything, and then
only inline (or out-of-line) items that profiling reveals work better.

> In code I'm writing at the moment, I have a fairly long function


If you make it shorter, then the odds increase that the function and the
functions it calls can all fit in the CPU cache. Making the function long,
inlining it, and inlining the functions it calls all might overflow the
cache, making things slower.

(If you make it shorter, you will also please anyone who must work with this
function. Long functions are worse than 'goto'.)

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
 
Reply With Quote
 
Phlip
Guest
Posts: n/a
 
      03-31-2006
Noah Roberts wrote:

> ItÂ*doesn't
> have to obey the inline keyword.


Including it doesn't have to obey the out-of-line situation. It could inline
things you declared out-of-line.

--
Phlip
http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      03-31-2006

"Tomas" <(E-Mail Removed)> wrote in message
news:geeXf.7752$(E-Mail Removed)...
> Howard posted:
>
>>
>> "Tomas" <(E-Mail Removed)> wrote in message
>> news:M0eXf.7750$(E-Mail Removed)...
>>>
>>>> If it is only invoked once, why care whether it is inlined or
>>>> not?
>>>> You will never be able to see a difference in performance.
>>>
>>> If it's called "outline", then the program counter will be moved.
>>>
>>> If it's called "inline", the control will simply flow into the
>>> function.
>>>
>>> -Tomas

>>
>> Are you saying that there's a discernable difference in performance
>> between making a function call and not making a function call, when
>> it's done ONCE? What, it'll take a millisecond longer? Forget about
>> it... program for readability, correctness, and maintainability. Only
>> worry about performance if you're having a performance problem.
>>
>> -Howard

>
> Yes, but I shouldn't throw performance out the window just because my
> code works.
>


But who said the performance of a single function call was a problem in the
first place?

> Let's say that it runs a milisecond longer:
>
> Now imagine we're decoding gigabytes of data, and that my "progam" is run
> twenty thousand times.
>
> 20000 x .001 = 20 seconds
>


20 seconds when processing gigabytes of data is hardly noticeable! Not to
mention that the overhead of simply running the program would FAR outweigh
such a performance penalty. And as was pointed out elsewhere, the cost of
the function call would be nowhere near a millisecond in any modern
computer.

You're welcome to worry about whatever you want to worry about, but if
you're asking advice here, you're going to get exactly one answer: it's not
worth your time to worry about, unless you have some reason to beleive it
actually IS affecting performance.

-Howard






 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having compilation error: no match for call to ‘(const __gnu_cxx::hash<long long int>) (const long long int&)’ veryhotsausage C++ 1 07-04-2008 05:41 PM
Use of Long and Long Long Bart C C Programming 27 01-15-2008 05:27 AM
long long and long Mathieu Dutour C Programming 4 07-24-2007 11:15 AM
unsigned long long int to long double Daniel Rudy C Programming 5 09-20-2005 02:37 AM
Assigning unsigned long to unsigned long long George Marsaglia C Programming 1 07-08-2003 05:16 PM



Advertisments