Single quoted vs double quoted string - PHP Views : 380
Tagged in : PHP
0 0
Send mail
Use single quoted strings unless you need to interpolate variables into your string. This saves PHP the time to scan the string for contained variables and saves about 50% execution time.


<?php
function getmicrotime($t) {

list($usec, $sec) = explode(" ",$t);

return ((float)$usec + (float)$sec);

}
$start = microtime();

$a = array();

for($i=0;$i<100;$i++) {

array_push($a, "Aaron rules!");

}
$end = microtime();

$t1 = (getmicrotime($end) - getmicrotime($start));

echo "
double quotes: $t1
";
unset($a);
$start = microtime();

$b = array();

for($i=0;$i<100;$i++) {

array_push($b, 'Aaron rules!');

}
$end = microtime();

$t2 = (getmicrotime($end) - getmicrotime($start));

$t3 = $t1-$t2;

echo "single quotes: $t2
difference...: $t3
";

?>


Results:

double quotes: 0.001505970954895
single quotes .: 0.00078308582305908
difference........: 0.00072288513183594
By Rekha, On - 2009-11-13



    Login to add Comments .