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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.