Use timestamp function to measure the speed of code. The timestamp function placed twice in a program one at starting of program and another at end of the program. Then the time difference between end time and start time is the actual speed of code. PHP uses microtime($get_as_float) function to measure the speed of code.
microtime($get_as_float): The microtime() function is an inbuilt function in PHP which is used to return the current Unix timestamp with microseconds. The $get_as_float is sent as a parameter to the microtime() function and it returns the string microsec sec by default.
microtime( $get_as_float )
Parameters: This function accepts single parameter $get_as_float which is optional. If $get_as_float is set to TRUE then it specify that the function should return a float, instead of a string.
Return Type: It returns the string microsec sec by default, where sec is the number of seconds since the Unix Epoch (0:00:00 January 1, 1970, GMT), and microsec is the microseconds part. If the $get_as_float parameter is set to TRUE, it returns a float representing the current time in seconds since the Unix epoch accurate to the nearest microsecond.
Example 1: This example use microtime() function to measure speed of code.
Example 2: This method uses time() function which returns time in seconds, not much accurate execution time can be measured.
- HTML | <code> Tag
- C# | How to get hash code for the specified key of a Hashtable
- Code introspection in Python
- HTML | DOM Code Object
- How to write a Pseudo Code?
- Dynamically generating a QR code using PHP
- Making a QR code for a website
- HTML | Computer Code Elements
- HTML | DOM KeyboardEvent code Property
- Code valid in both C and C++ but produce different output
- Different Python IDEs and Code Editors
- How to send HTTP response code in PHP?
- XSS Prevention : Without Writing Single Line of Code
- Displaying inline and multiline blocks of code using Bootstrap
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.