This is a discussion on Two related "performance" questions within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'm working on a program that permits a web site admin to enable either or both of its two ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm working on a program that permits a web site admin to enable either
or both of its two features. Both features have a reasonable amount of code. So - is it likely that someone will complain that having both sets of code loaded when only one of the features is enabled will reduce performance? Is there a significant advantage to splitting the code so that only one feature is loaded to run when only one feature is enabled? The php file is about 30KB (both features). Second - I tend to put a lot of comments in my code. In terms of file size, there is often more lines of comments than lines of code (unless the code is relatively trivial). Similarly - is someone likely to grump that loading all that text at run rime is inefficient? Mike |
|
|||
|
On 24 Mar, 21:50, Michael Daly <MichaelD...@foo.bar> wrote:
> I'm working on a program that permits a web site admin to enable either > or both of its two features. Both features have a reasonable amount of > code. > > So - is it likely that someone will complain that having both sets of > code loaded when only one of the features is enabled will reduce > performance? Is there a significant advantage to splitting the code so > that only one feature is loaded to run when only one feature is enabled? > The php file is about 30KB (both features). > not really > Second - I tend to put a lot of comments in my code. In terms of file > size, there is often more lines of comments than lines of code (unless > the code is relatively trivial). Similarly - is someone likely to grump > that loading all that text at run rime is inefficient? and no > > Mike but in general for other reasons it is a good idea to modularise your code, something like jpgraph - a huge set of classes that generates various types of graphs, simply separates its clsses according to the type of graph, its a split that makes sense to coders implementing it at the coal face, and to maintainters. It would be a nice little project to convert to OO, if not already, and yeah try separating it. |
|
|||
|
shimmyshack wrote:
Thanks for the info. > but in general for other reasons it is a good idea to modularise your > code, something like jpgraph Yeah - I've been sloppy up to now and all classes are defined in a single file. I intend to split it into one file per class. However, I figure that with all the require_once statements, at run time it will be like loading a single big file anyway, no? Mike |
|
|||
|
On Mar 25, 1:03 pm, Michael Daly <MichaelD...@foo.bar> wrote:
> shimmyshack wrote: > > Thanks for the info. > > > but in general for other reasons it is a good idea to modularise your > > code, something like jpgraph > > Yeah - I've been sloppy up to now and all classes are defined in a > single file. I intend to split it into one file per class. However, I > figure that with all the require_once statements, at run time it will be > like loading a single big file anyway, no? > > Mike That's what __autload is for: <http://www.php.net/autoload> Here's the idea: when a class is referenced and it isn't yet defined, the __autoload function is called with the class name. This gives you an opportunity to load it. Furthermore, you'll only end up loading what you need and you won't need all those require_once() statements. All my classes live in their own files where the file is named after the class. I have a file called autoload.php that I include at the top of all my pages. Inside I have something like this: if(!function_exists('__autoload')) { function __autoload($class_name) { require_once $class_name . '.php'; } } |