I'm a big fan of clean code and I use HEREDOCS plenty. I always see code from others where the context is changed from HTML to PHP and vice versa multiple times in the script.
Maybe I'm testing this wrong but I decided to time 3 simple scripts and changing context is the fastest by my results.
Script 1 - Averages .256 of a second
Script 2 - Averages .358 of a second
Script 3 - Averages .528 of a second
Am I doing something wrong or is changing context the performance way to go?
Maybe I'm testing this wrong but I decided to time 3 simple scripts and changing context is the fastest by my results.
Script 1 - Averages .256 of a second
Code:
<?PHP
for($i=1;$i<=100;$i++)
{
for($j=1;$j<=100;$j++)
{
?>Block <?PHP print $i;?> Number <?PHP print $j;?><br> <?PHP
}
}
?>
Script 2 - Averages .358 of a second
Code:
<?PHP
for($i=1;$i<=100;$i++)
{
for($j=1;$j<=100;$j++)
{
print"Block $i Number $j<br>";
}
}
?>
Script 3 - Averages .528 of a second
Code:
<?PHP
for($i=1;$i<=100;$i++)
{
for($j=1;$j<=100;$j++)
{
print <<<EOF
Block $i Number $j<br>
EOF;
}
}
?>
Am I doing something wrong or is changing context the performance way to go?