Jump to content

[SOLVED] Quesstion about speed in your script...


JJohnsenDK

Recommended Posts

Hey

 

I just want to know if your script gets slower if i opening and closing php everytime i need php between html code. Like this:

 

<div><?=$test['test'];?></div>

 

And say that i do this about 20 times in one page of code. Would it then be slower than if i wrote all the html in php. Like this:

 

<?php
   echo "<div>".$test['test']."</div>";
?>

 

Its propperly a simpel quesstion, but nice to know, right :)

Doing it the latter is better, but as long as there is not 50,000 calls it shouldn't matter.

 

Here is a way for you to test:

 

<?php

function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}

$time_start = microtime_float();
$test['test'] = "test";
for ($i=0; $i<10000;$i++) {
?>   
       <div><?=$test['test'];?></div>
<?php
}

$time_end = microtime_float();

$time = $time_end - $time_start;

echo "It took $time seconds to go in and out<br />\n";

$time_start = microtime_float();
$test['test'] = "test";
for ($i=0; $i<10000;$i++) {
       echo '<div>'. $test['test'] .'</div>';

}

$time_end = microtime_float();

$time = $time_end - $time_start;

echo "It took $time seconds to stay in<br />\n";
?>

 

Give that a try and see what the results are.

 

As far as I am concerned I would prefer the echo statement and not go in and out. Just makes it easier to debug etc.

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.