It would be nice to back up the quantification "MUCH" with some real data. Intuitively we all understand that a string that is parsed for possible variables will be taking more time than a constant which is taken as is.
However, HOW MUCH slower might be an insignificant amount of time.
Using the following test code (partly extracted from the PHP manual):
Code:
<?php
/*
compares runtimes of 2 functions
to use, copy/paste functions, and call them from fct1 and fct2
*/
$runtimes=100;//how many times to run the tests
function fct1(){
for($j=0; $j<10000; $j++) {
$str .= '!';
}
}
function fct2(){
for($j=0; $j<10000; $j++) {
$str .= "!";
}
}
//################################################################//
$time1=0;
for ($i=0;$i<$runtimes;$i++){
$time_start = array_sum(explode(' ', microtime()));
fct1();
$time_end = array_sum(explode(' ', microtime()));
$time1 = ($time1*$i+$time_end - $time_start)/($i+1);
}
echo "\nfct1 runs in $time1 ms.\n";
$time2=0;
for ($i=0;$i<$runtimes;$i++){
$time_start = array_sum(explode(' ', microtime()));
fct2();
$time_end = array_sum(explode(' ', microtime()));
$time2 = ($time2*$i+$time_end - $time_start)/($i+1);
}
echo "\nfct2 runs in $time2 ms.\n";
$tf = round($time2/$time1);
echo "\nfct".(($tf>1)?'1 is faster by a factor of '.$tf:(($tf<1)?'2 is faster by a factor of '.round($time1/$time2):'1 is roughly equal to fct2'))."\n\n";
?>
Result for 100 runs of each function concatenating a string 10K times:
fct1 runs in 0.016148986816406 ms.
fct2 runs in 0.016058847904205 ms.
fct1 is roughly equal to fct2
Result for 100 runs of each function concatenating a string 10K times fct2 with variable substitution:
fct1 runs in 0.020972301959991 ms.
fct2 runs in 0.025942962169647 ms.
fct1 is roughly equal to fct2
Result 100 runs of each function (same as above) but three substitutions in fct2 (three vars in the double quotes):
fct1 runs in 0.017860918045044 ms.
fct2 runs in 0.039006175994873 ms.
fct1 is faster by a factor of 2
So the statement should be:
Double quotes are only significantly slower when actual variable substitution takes place. The first test actually indicates thaqt double quotes without variable substitution are actually faster. However, if you print non dynamic strings with single or double quotes makes virtually no difference.