Log in

View Full Version : Code performance: which is faster ?



superjadex12
08-05-2006, 08:03 AM
Just asking for a second opinion on my theory.

Say I have 5 cases in a switch statement. And for each case I have a block of 1kb of code. Now if all this code was contained in this page I'd have a 5kb sized php document.

Now say I put my 1kb cases in separate pages and include them via include ()
This would make my main page ~ 1-2 kb. Would this make my page load faster?
The reasoning is 1. the page is smaller and 2. The 4 cases that aren't executed wont include the block of text at all ... ??

What do you guys think ?

Oh yeah and while I'm posting, if php is so good, and free, and powerful, why use any other server side? Obviously for the sake of choice/variety or something, but does any other code have any major advantages ?

Thanks

jscheuer1
08-05-2006, 08:07 AM
I'm not sure that you can include/not include pages dynamically using PHP. I think not. If not, your question is moot.

superjadex12
08-05-2006, 09:01 AM
just tested with XAMPP local host : php 5.1.1

It works!

Twey
08-05-2006, 01:48 PM
This would make my main page ~ 1-2 kb. Would this make my page load faster?There wouldn't be an improvement, since the joy of parsing as you go is that code that's never reached is never parsed, so it doesn't have a performance hit.
Oh yeah and while I'm posting, if php is so good, and free, and powerful, why use any other server side? Obviously for the sake of choice/variety or something, but does any other code have any major advantages ?Because PHP as a language is rather poor :) It has little in the way of standardisation of function names (for example, mysql_select_db and fsockopen); it lacks the object-orientation of other languages (although in fairness to it, it does seem to be trying now); and it's slow. People complain about the speed of Java, but according to several benchmarks, PHP is far slower.
Also, PHP is interpreted as it executes, every time. Something like JSP, by comparison, is compiled once when it's first accessed, then runs from bytecode. This is a lot more efficient for all subsequent calls.