Note Submitter: frank at interactinet dot com
----
using single quotes and concatenation can be faster than using double quotes.
<?php
$y = 'this is a test';
$x = "$y to see how concat compares";
// double quote test average for 10000 iterations: 0.001625 sec
$x = $y.' to see how concat compares';
// single quote plus concat test average: 0.001522 sec
?>
The concatenation was approx 7% faster.
Surprisingly, with more variables the concatenation becomes even better at 35% faster:
<?php
$x = "$y to see how concat compares $y";
// 0.002456641 sec average
$x = $y.' to see how concat compares'.$y;
// 0.00181675 sec average
?>
So, it is better to create strings with single quotes.
Here was the benchmark code:
<?php
for($j=0;$j<10;$j++)
{
$s = microtime(TRUE);
for($i=0;$i<10000;$i++)
{
$x = "$y to see how concat compares $y";
}
echo microtime(TRUE)-$s,'<br>';
}
echo '<br><br><br>';
for($j=0;$j<10;$j++)
{
$s = microtime(TRUE);
for($i=0;$i<10000;$i++)
{
$x = $y.' to see how concat compares'.$y;
}
echo microtime(TRUE)-$s,'<br>';
}
exit();
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.