Re: Re: functions versus includes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Frank Lopes wrote:
No takers on this topic?

The question is not one of performance since while it will be quicker to call a function than include a file the difference is going to be inconsequential.

If you were to use a function where would you put it? You imply it needs to be used from multiple scripts, so it would need to be in an included file anyway which makes the question kinda pointless.

Whether to use a function should then be based on how you need to use this "block of text". Will it be used more than once in any given script? If yes then you want a function so you only need to include the file once. If not then it really doesn't matter whether you use a function in the external file.

When you're thinking about possible performance issues there are two things you need to ensure...

1) You're not spending time optimising the wrong bit (this would be an example of that). You can check that by writing a quick performance test as someone did later in this thread. 90% of the time you'll find that the performance difference between two options is negligible.

2) The architecture and maintainability of your code is more important than most performance issues you can imagine.

Performance optimisation should be driven by performance problems. Write your app, test it, find bottlenecks and then optimise those. Time spent saving 0.001 seconds per request is better spent elsewhere.

-Stut

--
http://stut.net/

""Frank Lopes"" <franklopes@xxxxxxxxxxx> wrote in message news:8E.57.64752.7EC06374@xxxxxxxxxxxxxxx
I just started using PHP and got to think...

Without getting into the discussion of "best practices", strictly from a performance perspective,
what is faster: a function or an include?

For example I have a block of text that needs to appear mutliple times throughout the site.

Will I be better off creating a function with its contents and then later just calling the function or, will it be faster (from an execution perspective) for me to create an .inc file that gets included later on?

Thanks for the your thoughts.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux