Performance
The cost of calling function is small or large depending on how you look. In general the cost is to save some registers in memory (most likely will be in the L1 cache which is very fast) and then recover the original state of the registers before the end of it.
In addition there may be copies of data because of parameter passing. If this would not occur if it were not a function, it depends on the situation, some cases the copy is mandatory even without the function.
Under certain circumstances the compiler can linearize the function, that is, instead of calling her (call) it copies the function code to the place you were calling. You will achieve readability and performance.
If the compiler does not do this it is because it cannot or does not compensate to do the inline of the function (ok, there are situations that the human knows can or compensates, and the compiler does not).
In the question linked above I speak of it. If the function is not lowercase and run for a very short time does not compensate. Nor does it pay to optimize what will be called a few times, but this is not always possible for the compiler.
The programmer may know until something is called many times but actually in a lot of place there is natural waiting, so performance does not matter.
It is true that on devices with reduced capabilities it can be useful to do a little more optimization. Optimization can be much worse in these cases, because if you gain performance you lose memory and little memory greatly affects performance. And one of the scarce features is battery. Faster code is usually more economical code.
In the past, when computers were less powerful, this was far more important.
Performance is negligible in most cases and where it is not, the compiler helps you. Of course there may be case that the performance is bad, but the most likely is that the algorithm is bad and not the call of the function that is disturbing.
There are cases in which the linearization of the function can cause extra costs and what seemed a certain performance gain, the opposite is true. And as the difference is very small, the programmer "smart guy" who did what he thought would give better performance ends up not even realizing that he did the worst, although this worst one also will not disturb much.
Readability
I will never say forever prefer to reproduce the code than to call it, but rarely is this necessary and should only do so after verifying that the performance is not expected (has to measure). The cost of optimizing may not compensate for the gain. Because maintenance becomes more difficult. You break the DRY.
Of course also between the readable with less performance and the readable with more performance I prefer the more performance. But copying the code to avoid the call will hardly be more readable than calling it.
Languages
If one uses PHP, mainly, or Java or C# it does not want the maximum performance. These languages can be fast, they can benefit from this optimization, but it’s not so common to need it. When you need a lot of performance in general, C or C++ is preferred. In these languages it makes but sense to eliminate function calls, but it depends on the application, depends on the point of the application.
Memoriam
The question talks about memory consumption as well. The function will use more memory to save the registers and it is possible that it will also spend a little more because of the copy of parameters, but not always. If the code was done right it doesn’t matter, because the memory used is from stack which is already allocated, using or not.
Profilling
You need a profiler to check how the code is running and indicate the costs. Valgrind is the best known for Linux and for Windows should probably be using Visual Studio which has a profiler.
There are other ways, but this is the most accurate and correct.
Idiot definition: Person who uses performance/performance as a lame excuse for not following good programming practices and writing rogue code.
– Victor Stafusa
Ah, and those people who don’t follow good practices by insisting on hitting the performance/performance key invariably don’t have the slightest idea of what the process should be to measure what they stand for.
– Victor Stafusa
@Victorstafusa, I agree with you. Performance is something important, but it should not prevent you from writing a minimally legible code.
– jlHertel
I gave +1 in all the answers, because they were all satisfactory. I marked Bigown’s as the correct one, because it seemed to me to be the most complete
– jlHertel
Performance is something relative, you have to look closer, without a scenario, you can’t tell if it makes a difference or not. 10ms in a google indexing routine is one thing, 10ms in a book register that has 10 users is another. Generally, this discussion of valley or not to do is done in legacy code and the guys are not very keen to refatorar (have work). But, there are many situations where code written following 'patterns' will actually be slower than code that only has a main :P (generalizing). In your case, memory management seems to be the most glaring.
– Intruso