I was just wondering if anyone has any guidelines or rules-of-thumb on how many included functions is too many?
I have about 10 or 12 functions that I use across say 30 pages. Is it better to group them all in one include file, break them up into say 3 or 4 different include files (if possible), or nest them (grouping them by what they do -- i.e., file manip functions, DB functions, etc.) I know this doesn't seem like a lot of includes, but I expect the number to grow substantially and I would like to settle on a general approach before it grows much more.
It would seem that nesting them would be the most orderly way, but would that affect the speed or performance of the scripts?
In other words, is the script slowed down by the functions it does not use or by too many file inclusions?
Thanks,
(P.S., Although this isn't a code question, I wasn't sure it should go in Theory and Design either since the question is not "advanced").
Grouping Included Functions-How much is too much? [RESOLVED]
Moderator: General Moderators
Grouping Included Functions-How much is too much? [RESOLVED]
Last edited by opengavel on Thu Sep 21, 2006 11:01 am, edited 1 time in total.
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
I would group them by what they do, and include them all. This way the code would be most readable.
I think
is better than
or
I think
Code: Select all
include('functions/db.php');
include('functions/manip.php');Code: Select all
include('functions/one.php');
include('functions/two.php');
include('functions/three.php');
include('functions/four.php');Code: Select all
include('functions.php');Thanks for the replies.
I am still wondering a couple of things:
1. Is a PHP script slowed down by unused functions?
2. Even if I group them by topic and include them, do others generally include all the functions or just the groups that include functions you know you will use? I assume the answer to this depends on the first question.
3. Lastly, does anyone have a simple script that can output a script's execution time, so I can measure the speed difference, if any?
Thanks again
I am still wondering a couple of things:
1. Is a PHP script slowed down by unused functions?
2. Even if I group them by topic and include them, do others generally include all the functions or just the groups that include functions you know you will use? I assume the answer to this depends on the first question.
3. Lastly, does anyone have a simple script that can output a script's execution time, so I can measure the speed difference, if any?
Thanks again
Unless you are including massive (and I mean MASSIVE) amounts of unused functions, you won't notice a difference.
Calculating execution time is easy
Top of script:
End of Script:
Calculating execution time is easy
Top of script:
Code: Select all
$begin = microtime();Code: Select all
$end = microtime();
$elapsed = $end - $begin;
echo "Execution Time: " . $elapsed . " milliseconds";-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
PHP in terms of execution wouldn't be slowed by unused functions, but parsing time is increased and therefore does effect your overall PHP performance. Reduce the amount of unused functions as much as possible.
Modularity is key to PHP development success.
Files under ext2 FS are actually accessed faster when they fall under the 12*1024 bytes rule. Meaning large files are accessed slower than small files (1024*12 = 12228 bytes OR LESS) so modularity, although requiring more includes and thus more wasted disk space *can* actually be faster in terms of overall execution.
Modularity is key to PHP development success.
Files under ext2 FS are actually accessed faster when they fall under the 12*1024 bytes rule. Meaning large files are accessed slower than small files (1024*12 = 12228 bytes OR LESS) so modularity, although requiring more includes and thus more wasted disk space *can* actually be faster in terms of overall execution.