note 74627 deleted from language.types.string by felipe
| From: | felipe@php.net | Date: | Sun, 23 Mar 2008 23:15:32 +0000 |
| Subject: | note 74627 deleted from language.types.string by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137442@lists.php.net to get a copy of this message | ||
Note Submitter: maikel7 at poczta dot onet dot pl
----
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.