note 74257 added to language.types.string

From: Date: Sun, 01 Apr 2007 15:44:06 +0000
Subject: note 74257 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-125007@lists.php.net to get a copy of this message
A simple benchmark to check differents about : - simple and double quote concatenation and - double quote and heredoc replacement <?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 = 2000; for( $i=0; $i<$iter; $i++ ) test_simple_quote_concat(); for( $i=0; $i<$iter; $i++ ) test_double_quote_concat(); for( $i=0; $i<$iter; $i++ ) test_double_quote_replace(); for( $i=0; $i<$iter; $i++ ) test_eot_replace(); ?> I've use xdebug profiler to obtain the followed results: test_simple_quote_concat : 173ms test_double_quote_concat : 161ms test_double_quote_replace : 147ms test_eot_replace : 130ms ---- Server IP: 194.246.101.61 Probable Submitter: 82.236.114.103 ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/74257 Del: integrated -- https://master.php.net/note/delete/74257/integrated Del: useless -- https://master.php.net/note/delete/74257/useless Del: bad code -- https://master.php.net/note/delete/74257/bad+code Del: spam -- https://master.php.net/note/delete/74257/spam Del: non-english -- https://master.php.net/note/delete/74257/non-english Del: in docs -- https://master.php.net/note/delete/74257/in+docs Del: other reasons-- https://master.php.net/note/delete/74257 Reject -- https://master.php.net/note/reject/74257 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125007) next »