我正在检查这 4 个具有相同变量的字符串的执行时间差异:
$name= "rahul";
echo "My name is $name"
echo "My name is ".$name;
echo "My name is {$name}";
echo "My name is '{$name}'";
但每次我尝试它时,我只得到 3 或 4 个随机答案,即。 0 或 0.00099992752075195 或 0.0010001659393311
我的代码是:
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$name = 'rahul' ;
$time_start = microtime_float();
echo "My name is $name"; // First style
$time_end = microtime_float();
$time = $time_end - $time_start;
echo " // $time seconds\n ";
$time_start2 = microtime_float();
echo "My name is ".$name; // Second style
$time_end2 = microtime_float();
$time2 = $time_end2 - $time_start2;
echo " // $time2 seconds\n ";
$time_start3 = microtime_float();
echo "My name is {$name}"; // Third style
$time_end3 = microtime_float();
$time3 = $time_end3 - $time_start3;
echo " // $time3 seconds\n";
$time_start4 = microtime_float();
echo "My name is '{$name}'"; // Fourth style
$time_end4 = microtime_float();
$time4 = $time_end4 - $time_start4;
echo " // $time4 seconds\n";
?>
我通过 cmd 计算它,我的输出是:
C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0 seconds My name is rahul // 0 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0 seconds My name is rahul // 0 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0.00099992752075195 seconds My name is rahul // 0 seconds My name is rahul // 0 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0 seconds My name is rahul // 0 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is rahul // 0.0010001659393311 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is rahul // 0.00099992752075195 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is rahul // 0.00099992752075195 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0.00099992752075195 seconds My name is rahul // 0 seconds My name is rahul // 0 seconds My name is 'rahul' // 0.00099992752075195 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0.00099992752075195 seconds My name is rahul // 0 seconds My name is rahul // 0 seconds My name is 'rahul' // 0.0010001659393311 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0.0010001659393311 seconds My name is rahul // 0.00099992752075195 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0.00099992752075195 seconds My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is 'rahul' // 0.0010001659393311 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0 seconds My name is rahul // 0.0010001659393311 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is rahul // 0 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>php q.php My name is rahul // 0 seconds My name is rahul // 0.00099992752075195 seconds My name is rahul // 0.00099992752075195 seconds My name is 'rahul' // 0 seconds C:\wamp\www\my_jquery>
为什么我用不同的语句一次又一次地得到相同的输出。