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

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

Common xlabel/ylabel for matplotlib subplots

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

12 answers

NUMPYNUMPY

Flake8: Ignore specific warning for entire file

12 answers

NUMPYNUMPY

glob exclude pattern

12 answers

NUMPYNUMPY

How to avoid HTTP error 429 (Too Many Requests) python

12 answers

NUMPYNUMPY

Python CSV error: line contains NULL byte

12 answers

NUMPYNUMPY

csv.Error: iterator should return strings, not bytes

12 answers


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

sin

How to specify multiple return types using type-hints

exp

Printing words vertically in Python

exp

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

cos

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically