Jump to content

Speed Question


Mateobus

Recommended Posts

Hey all, I have a speed question, here are two code snippets, which will run faster?
---------------------------- Code --------------------------------
// This is Option 1
<html>
Name:<?php echo $Name; ?> <br />
School:<?php echo $school; ?> <br />
</html>
----------------------------End Code ----------------------------

---------------------------- Code --------------------------------
// This is Option 2
<html>
<?php
echo “Name: $Name <br />”.
“School: $School <br />”;
?>
</html>
----------------------------End Code ---------------------------
This is a very simplified version of the issue i am dealing with. For example, if I am writing complicated html code that creates tables, should I write that using a php echo statement, or use html and make several php calls for each piece of data...

Hope you understand the question that I am asking. Thanks
Link to comment
https://forums.phpfreaks.com/topic/10538-speed-question/
Share on other sites

Why don't you test it to find out?

[code]
<?php
function timer()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}


$Name = "Donald Duck";
$School = "Slough Grammar";

$t1 = timer();
for ($i=0; $i<1000; $i++) {
?>
    Name:<?php echo $Name; ?> <br />
    School:<?php echo $School; ?> <br />
<?php
}
$t2 = timer();
for ($i=0; $i<1000; $i++) {
    echo "Name: $Name <br />".
    "School: $School <br />";
}
$t3 = timer();

$total1 = $t2-$t1;
$total2 = $t3-$t2;
echo "Option 1 :  $total1 <br />";
echo "Option 2 :  $total2 <br />";
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/10538-speed-question/#findComment-39325
Share on other sites

Interesting...Several page refreshes say that option 2 takes longer.

Option 1 : 0.0028409957885742
Option 2 : 0.0035510063171387

Option 1 : 0.0027570724487305
Option 2 : 0.0030298233032227

Option 1 : 0.0025520324707031
Option 2 : 0.0031177997589111

thanks for the timer code, looks like i go the faster server barand!
Link to comment
https://forums.phpfreaks.com/topic/10538-speed-question/#findComment-39492
Share on other sites

results on my server:

Option 1 : 0.23969197273254
Option 2 : 0.097437143325806

Option 1 : 0.26200318336487
Option 2 : 0.1240758895874

Option 1 : 0.23777079582214
Option 2 : 0.095417976379395

option 2 seems to be significantly faster on my server :/

well it's a good thing i tend to write my scripts in the form of option 2 anyways [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]
Link to comment
https://forums.phpfreaks.com/topic/10538-speed-question/#findComment-39507
Share on other sites

[b]Dev - Windows laptop[/b]
Option 1 : 3.17229294777
Option 2 : 0.764003038406

Option 1 : 1.86993980408
Option 2 : 0.345380067825

Option 1 : 1.91975998878
Option 2 : 0.444586038589

[b]QA/Prod - Linux Virtual Instance[/b]
Option 1 : 0.87854886054993
Option 2 : 0.3418550491333

Option 1 : 1.7756929397583
Option 2 : 0.92465806007385

Option 1 : 0.51655387878418
Option 2 : 0.49194598197937
Link to comment
https://forums.phpfreaks.com/topic/10538-speed-question/#findComment-39668
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.