Would this code be quicker (or slower)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

Would this code be quicker (or slower)

Post 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");}
?>
?>
User avatar
phpcoder
Forum Contributor
Posts: 158
Joined: Sat Nov 02, 2002 1:18 pm
Location: Manchester, UK

Post 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 .
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

more bandwidth? why? those files arent local?

if they are local... it will be very quick!!
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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).
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

how much data you talk about?

Post 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.
-
Post Reply