Hello everyone,

Knowing how much most of you like using double quotes I though to test
it a bit.
I was writing an article for PHPBeginner.com and made this interesting
proven conclusion:

Concatenating single quotes is faster unless you concatenate them more
than two.
Then game changes into the double quotes side.

Sure, this is a miserable difference when doing a few print()s, but when
you loop a lot it DOES change the game.

Hope this was interesting to someone.



Here's the code I was playing with.

<?
$limit = !$limit ? 1000 : $limit;
$what = 'test';

include_once('timer.inc'); // just a simple timer taken from WeberDev

$singe_escape  =  new  c_Timer;  
$double_escape  =  new  c_Timer;  
$double_no_escape  =  new  c_Timer;  
$double_curly_escape  =  new  c_Timer;  


$var = '';
$singe_escape->start();
for($i=0; $i<$limit; $i++) {
        $var .= 'this is the '.$what.' of concatenation '.$i.' in the
strings';
}
$singe_escape->stop();


$var = '';
$double_escape->start();
for($i=0; $i<$limit; $i++) {
        $var .= "this is the ".$what." of concatenation ".$i." in the
strings";
}
$double_escape->stop();


$var = '';
$double_no_escape->start();
for($i=0; $i<$limit; $i++) {
        $var .= "this is the $what of concatenation $i in the strings";
}
$double_no_escape->stop();


$var = '';
$double_curly_escape->start();
for($i=0; $i<$limit; $i++) {
        $var .= "this is the {$what} of concatenation {$i} in the
strings";
}
$double_curly_escape->stop();


echo 'singe_escape <B>'.$singe_escape->elapsed().'</B><BR>';
echo 'double_escape <B>'.$double_escape->elapsed().'</B><BR>';
echo 'double_no_escape <B>'.$double_no_escape->elapsed().'</B><BR>';
echo 'double_curly_escape
<B>'.$double_curly_escape->elapsed().'</B><BR>';

?>



Maxim Maletsky
www.PHPBeginner.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to