Page 1 of 1

Would this code be quicker (or slower)

Posted: Sat Jan 17, 2004 3:16 pm
by lizlazloz
ok, say i have code like this:

Code: Select all

<?php
if (something is something)
{do big bit of code}
else
{do other big bit of code}
?>
would it use more bandwidth/be quicker to do this, or not:


Code: Select all

<?php
if (something is something)
include("phpfilewithcodein.php");
else
{include("otherphpfilewithcodein.php");}
?>
?>

Posted: Sat Jan 17, 2004 3:24 pm
by phpcoder
I think both will be same coz "include" also put that file in ur maine calling file so i think both will b same . but using include is better .

Posted: Sat Jan 17, 2004 3:24 pm
by AVATAr
more bandwidth? why? those files arent local?

if they are local... it will be very quick!!

Posted: Sat Jan 17, 2004 3:27 pm
by McGruff
The second method adds a HD access to read an included file.

On the other hand, the second method doesn't have to parse both blocks of code - just the one triggered by the if test.

However the differences are not significant. Efficiency is rarely an issue.

It's probably a good practice to stick a timer on scripts so you can get a feel for what is and isn't important. There's a handy function in the php manual (look under getmicrotime).

how much data you talk about?

Posted: Sat Jan 17, 2004 3:33 pm
by djot
-
Hi,

how much data you talk about?

If it's normal sizes like 100kb it's no difference. If you talk about several MB I would strongly recommend the second choice.

It's code or only data?

djot

PS: bandwidth is dependend on output which should be the same in both cases.
-