In response to the discussion in [url=http://www.webdeveloper.com/forum/showthread.php?t=111268]this thread
Test script:
[code=php]
<?php
header(“Content-Type: text/plain”);
function single_quote()
{
$start = microtime(TRUE);
$string = ‘This is a test. It is only a test. Testing 1, 2, 3. ‘.
‘This has been a test. It was only a test. 3, 2, 1, the end.’;
return(microtime(TRUE) – $start);
}
function double_quote()
{
$start = microtime(TRUE);
$string = “This is a test. It is only a test. Testing 1, 2, 3. “.
“This has been a test. It was only a test. 3, 2, 1, the end.”;
return(microtime(TRUE) – $start);
}
function heredoc_str()
{
$start = microtime(TRUE);
$string = <<<EOD
This is a test. It is only a test. Testing 1, 2, 3.
This has been a test. It was only a test. 3, 2, 1, the end.
EOD;
return(microtime(TRUE) – $start);
}
$seed = microtime(TRUE); // because first call is always slow
$methods = array(‘single_quote’, ‘double_quote’, ‘heredoc_str’);
for($ix=0; $ix<20; $ix++)
{
array_rand($methods);
foreach($methods as $method)
{
$times[$method][] = call_user_func($method);
}
}
$methods = array(‘single_quote’, ‘double_quote’, ‘heredoc_str’);
foreach($methods as $method)
{
$averages[$method] = sprintf(“%01.6f”,
array_sum($times[$method]) / count($times[$method]));
}
echo “Averages (seconds):n”;
print_r($averages);
echo “nRaw Data:n”;
print_r($times); // show raw data
?>
Typical Results (run the script yourself if you want to see the raw data section):
[code]
Averages (seconds):
Array
(
[single_quote] => 0.000036
[double_quote] => 0.000035
[heredoc_str] => 0.000076
)
This was run on my awesomely un-powerful 500MHz Pentium III with a non-whopping 256MB of RAM, running PHP 5 on Apache. As a result of this, I’m not going to lose any sleep over the difference between single or double quotes, but will only use heredoc when necessary.