note 74627 added to language.types.string

From: Date: Fri, 20 Apr 2007 19:45:43 +0000
Subject: note 74627 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-125709@lists.php.net to get a copy of this message
I was curious about speed differences between "some text $var" and "some text".$var. And my tests seem to be quite the opposite to the benchmarks posted below by "php at moechofe dot com". I used this code: <?php function microtime_float() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $str = "some text"; $time_start = microtime_float(); for ($i=0; $i<100000; $i++) { $a="x $str o $str a $str d $str f $str"; } $duration1 = microtime_float() - $time_start; $time_start = microtime_float(); for ($i=0; $i<100000; $i++) { $a="x ".$str." o ".$str." a ".$str." d ".$str." f ".$str; } $duration2 = microtime_float() - $time_start; ?> On a windows machine $duration1 is about 2.5x greater (=slower) than $duration2. I ran it also on several hosting servers (Linux-based) and the differnces were smaller but still $duration1 was much greater. Only on one of the hosts where they use eAccellarator there was no difference between the two methods. So my conclusion is not to use "$variables in double-quoted strings" wherever speed is important. ---- Server IP: 83.64.128.68 Probable Submitter: 83.175.191.52 ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/74627 Del: integrated -- https://master.php.net/note/delete/74627/integrated Del: useless -- https://master.php.net/note/delete/74627/useless Del: bad code -- https://master.php.net/note/delete/74627/bad+code Del: spam -- https://master.php.net/note/delete/74627/spam Del: non-english -- https://master.php.net/note/delete/74627/non-english Del: in docs -- https://master.php.net/note/delete/74627/in+docs Del: other reasons-- https://master.php.net/note/delete/74627 Reject -- https://master.php.net/note/reject/74627 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125709) next »