news_yodpeirs@xxxxxxxxxxxx wrote: > I got different portions of code only used for certain purposes (who don't > ;-)?). But what, in your opinion (better: in your experience) would be the > best regarding script-performance: Putting each code-portion in a separate > file and include it if required, putting it in a constant-dependent > if-structure (if (defined('FOO') && FOO) {class foo{}; function foo(); ...}) defining functions or classes conditionally is not recommended, because it means they can only be defined at runtime and not compile time ... which will kill any op-code caching you might have in place or use in future (e.g. php.net/apc) > or simply let it be parsed every time? > > My first choice is using separate files, but if a file e.g. only contains 20 > lines, I fear it would take much longer to include the file against simply > parsing these lines in the existing file. And as parsing is done really > fast, there might be no real performance-loss in case of not using the > mentioned code. With the constant-dependent if-structure I don't know if > there are any performance-benefits if FOO isn't defined or defined as FALSE. > > Looks for me a bit like a philosophical question, but maybe you have > something to say about it nevertheless. A good thing for me would be > something like: up to 125 lines of code you get an adequate performance with > simply parsing it every time, with more than 125 lines you would get a > better performance with using separate files - just kidding, surely the > number of lines in this case is 42 ;-). for a few 1000 lines of code the difference is probably not measurable in any meaningful way (a spam assassin deamon, or something similar, hogging the CPU will probably have more realworld effect on the speed of your script). when your app becomes very large you will probably benefit from only including little used code when it is actually required. there is also the issue of maintainability - having to check and keep track of include/require statements scattered all through the code, and working through 'undefined class/function' errors when enhancing/bugfixing/refactoring code maybe alot more hassle than using a single global 'init' script that includes pretty much everything bit of code your scripts might need. personally I tend to go for maintainability over performance if the choice is mutually exclusive - generally your time is alot more costly than the purchase and placement of extra RAM, faster CPU, faster disks, etc. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php