FYI = ( Single_Concatenated_Q*2<=Double_Parsed_Q*2 );
| From: | Maxim Maletsky | Date: | Sat, 06 Oct 2001 02:27:25 +0000 |
| Subject: | FYI = ( Single_Concatenated_Q*2<=Double_Parsed_Q*2 ); | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-70177@lists.php.net to get a copy of this message | ||
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