note 78150 added to language.types.string
| From: | mouse at windworld dot ru | Date: | Sun, 30 Sep 2007 15:00:13 +0000 |
| Subject: | note 78150 added to language.types.string | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130947@lists.php.net to get a copy of this message | ||
I'm used the following code:
<?php
function test_simple_quote_concat()
{
$b = 'string';
$a = ' string'.$b.' string'.$b.' srting'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
$a .= ' string'.$b.' string'.$b.' string'.$b;
}
function test_double_quote_concat()
{
$b = "string";
$a = " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
$a .= " string".$b." string".$b." string".$b;
}
function test_double_quote_replace()
{
$b = "string";
$a = " string$b string$b string$b
string$b string$b string$b
string$b string$b string$b
string$b string$b string$b
string$b string$b string$b
string$b string$b string$b
string$b string$b string$b
string$b string$b string$b";
}
function test_eot_replace()
{
$b = <<<EOT
string
EOT;
$a = <<<EOT
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
string{$b} string{$b} string{$b}
EOT;
}
$iter = 100000;
$time_start = microtime(1);
$time_start = microtime(1);
for( $i=0; $i<$iter; $i++ )
test_double_quote_concat();
$duration2 = microtime(1) - $time_start;
$time_start = microtime(1);
for( $i=0; $i<$iter; $i++ )
test_double_quote_replace();
$duration3 = microtime(1) - $time_start;
$time_start = microtime(1);
for( $i=0; $i<$iter; $i++ )
test_eot_replace();
$duration4 = microtime(1) - $time_start;
$time_start = microtime(1);
for( $i=0; $i<$iter; $i++ )
test_simple_quote_concat();
$duration1 = microtime(1) - $time_start;
echo 'simple_quote_concat: '.$duration1." s\n";
echo 'double_quote_concat: '.$duration2." s\n";
echo 'double_quote_replace: '.$duration3." s\n";
echo 'eot_quote_replace: '.$duration4." s\n";
?>
And got very different results. Compare it yourself.
$ php test.php
simple_quote_concat: 0.853082895279 s
double_quote_concat: 0.896748065948 s
double_quote_replace: 0.708463907242 s
eot_quote_replace: 0.735204935074 s
$ php test.php
simple_quote_concat: 0.786070823669 s
double_quote_concat: 0.800376176834 s
double_quote_replace: 0.659599065781 s
eot_quote_replace: 0.674590110779 s
$ php test.php
simple_quote_concat: 0.819690942764 s
double_quote_concat: 0.842829942703 s
double_quote_replace: 0.659816980362 s
eot_quote_replace: 0.756074905396 s
$ php test.php
simple_quote_concat: 0.785160064697 s
double_quote_concat: 0.77215385437 s
double_quote_replace: 0.659204006195 s
eot_quote_replace: 0.67343211174 s
As you can see, simple and double quoted strings very close to each other.
----
Server IP: 195.54.192.44
Probable Submitter: 81.195.18.174
----
Manual Page -- http://www.php.net/manual/en/language.types.string.php
Edit -- https://master.php.net/note/edit/78150
Del: integrated -- https://master.php.net/note/delete/78150/integrated
Del: useless -- https://master.php.net/note/delete/78150/useless
Del: bad code -- https://master.php.net/note/delete/78150/bad+code
Del: spam -- https://master.php.net/note/delete/78150/spam
Del: non-english -- https://master.php.net/note/delete/78150/non-english
Del: in docs -- https://master.php.net/note/delete/78150/in+docs
Del: other reasons-- https://master.php.net/note/delete/78150
Reject -- https://master.php.net/note/reject/78150
Search -- https://master.php.net/manage/user-notes.php