let me explain my question this way…
I have a piece of html block which I want to reuse it several times in my app.
here I have 2 choices…
number 1 is to define a function in my functions file and put the html code in that function. and every time I need the html I call the function.
number 2 is to write my html inside another file and every time I need it I include it in my script.
what I want to know is which way is faster and use less resources?
btw I use PHP but I don’t think that is relevant. I think my question applies to other languages as well.
In general, it would be faster to include it in a function. If you include the file each time it adds the overhead of needing to open and read the file; with a function it’s just copying a bit of memory around.
I think that this is usually the case with PHP; certain servers and languages can be configured to optimize the include, but the function is almost always at least as fast.