Change language

How do I measure the speed of PHP code?

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 
    

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method