English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2006-08-04 12:20:30 · 3 answers · asked by www.tastyseed.com 2 in Computers & Internet Programming & Design

msa bromo had it right.

I just wanted a second opinion on the view that if all elements of an if or switch statement were includes, then all the cases that return FALSE will never get included. Would this be a good way of making the page leaner? Say I had 5 cases in a switch statement all with 1kb of code.
So adding 5 includes would say 4 kb of code not parsing ? Faster yes ??? or in practice no ?

2006-08-04 20:28:40 · update #1

3 answers

I think you will have to put together a benchmark test to see how long it takes a script to execute when designed different ways. There are several issues to consider...

1) You have to weigh the performance time against development time. There is a great benefit to segmenting and separating distinct functions into groups of related code, in sub-folders and files to be included. This becomes more and more important as the size of the application grows. On a large project, forethought and planning and organization (time saved on the design end) have to be weight against optimization (time saved on the execution end).

2) From a purely performance standpoint, you'll have to weigh the overhead of the code inside the IF block being compiled each time against the overhead of the file system having to find and open the file to be included. The issues there would be (a) allocating a new system resource to open the file, (b) checking that the proper permission is there to read the file, and (c) just how many files are in the include folder, that the server has to parse through to find the one you want?

2006-08-05 05:06:22 · answer #1 · answered by Anonymous · 0 0

Only in the sense that depending on the result of if statement, you may sometimes not need to process the include.

If that's an issue though, you may want to look into using a PHP opcode cache like APC (http://us2.php.net/apc).

Then the results of compiling the include file into opcodes will be cached and that will make it faster to include.

2006-08-04 19:31:14 · answer #2 · answered by msabramo 2 · 0 0

No exactly what do you mean...
something like:

if (!@include_once("loader.php"))
{
die("Fatal Error: Cant Load loader.php");
}

is used to load the file into memory, allowing you to just include it and not recode it all, if you mean this previous method vs writing the whole code over again...the answer is obvious, faster the include but I really think im missing the point here

2006-08-04 19:29:37 · answer #3 · answered by purefan 2 · 0 0

fedest.com, questions and answers