I was checking the difference in execution time of these 4 strings with same variable:
$name= "rahul";
echo "My name is $name"
echo "My name is ".$name;
echo "My name is {$name}";
echo "My name is '{$name}'";
But every i tried it i got only 3 or 4 random answers ie. 0 OR 0.00099992752075195 OR 0.0010001659393311
My code is :
<?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";
?>
I was calculating it through cmd and my output was:
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>
why am i getting same output again and again with different statements.