microtime ($get_as_float) :microtime() function - it is a built-in function in PHP that is used to return the current Unix timestamp with microseconds. $Get_as_float is sent as a parameter to the microtime() function and returns the default string in microseconds.
Syntax:microtime ($get_as_float)
Parameters:This function takes one parameter, $get_as_float, which is optional. If $get_as_float is TRUE, this indicates that the function should return a floating point number instead of a string.
Return type:by default returns a string microsecond sec, where sec - is the number of seconds since the beginning of the Unix epoch (0:00:00 January 1, 1970 GMT), and the microsecond - part of a microsecond. When $get_as_float is set to TRUE, it returns a floating point value representing the current time in seconds since the beginning of the Unix epoch with precision to the nearest microsecond.
Example 1: Inthis The example uses the microtime() function to measure the speed of the code.
// Use the microtime() function to measure
// start time
$time_start
= microtime (true);
// Program code
$num
= 0;
for
(
$i
= 0;
$i
< 100000000;
$i
+ = 1) {
$num
+ = 10;
}
// Use the microtime() function to measure
// end time
$time_end
= microtime (true);
// Time difference
$time
=
$time_end
-
$time_start
;
echo
$time
;
?>
Exit:4.1413249969482 Example 2.This method uses time(), which returns the time in seconds, but you can measure not very accurate execution time.
// Use the time() function to measure
// start time
$time_start
= time();
// Program code
$num
= 0;
for
(
$i
= 0;
$i
< 100000000;
$i
+ = 1) {
$num
+ = 10;
}
// Use the time() function to measure
// end time
$time_end
= time();
// Time difference
$time
=
$time_end
-
$time_start
;
echo
$time
;
?>
Exit:4