note 78150 deleted from language.types.string by felipe

From: Date: Sun, 23 Mar 2008 23:16:31 +0000
Subject: note 78150 deleted from language.types.string by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-137444@lists.php.net to get a copy of this message
Note Submitter: mouse at windworld dot ru ---- 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.

« previous php.notes (#137444) next »