However, this method is quite restrictive and cannot be used in a wide range. it requires a lot of code to be written every time and is suitable for simple debugging. For more information, see The PHP Manual.
2. you can use the benchmark_Timer class to get the time difference before and after code execution. you can get the execution time of N lines of code at the same time. The operation is simple and you only need to add a marker mark, see the usage instructions of the Benchmark_Timer class below.
How to use the Benchmark_Timer class
The Benchmark_Timer class only needs to add the Benchmark_Timer class initialization declaration and marker annotation to the debugging file. the execution time of each annotation is printed at the end of the file. The example is as follows:
There are two ways to print the result:
One is table output., $ Timer-> display (); such
Manual var_dump or print_r printing, $ Timer-> getProfiling ();, print_r function printing as shown in
1. name indicates the annotation name. the preceding two special annotations start and stop indicate the start and end, and the second is the custom annotation marker 01 marker 02.
2. time indicates the current microsecond time.
3,Diff indicates the execution time from the last tag to the current tagThis is the time difference we need to obtain. that's right. it's the value.
4. total indicates the entire execution time to the current time.
How to use the Benchmark_Iterate class
The Benchmark_Iterate class is used to debug the average time of function execution. Unlike the Benchmark_Timer class, the Benchmark_Timer class can call the same function multiple times to obtain the average execution time. The example is as follows:
Call the test function 100 times to obtain the average execution time. The result is as follows:
1. each number indicates the time of each call.
2. mean indicates the average time for function execution. The average time for calling the test function for 100 times is 0.000476.
3. iterations indicates the number of function calls.
How to use the Benchmark_Profiler class
The Benchmark_Profiler class is used to count the number of function executions and execution time. The example is as follows:
The result is as follows:
Benchmark_Profiler class is not used in actual performance debugging, because there are better tools such as xDebuger, so you can ignore them directly!
The Benchmark tool class is very useful for analyzing program performance problems in line-by-line Debugging. it mainly uses the Benchmark_Timer class to debug the time points of each code segment, to optimize the program and improve the code performance by obtaining the execution time. I will not discuss it in depth here. if you have any questions during use, please join us!
If you find this kind of line-by-line debugging very tired and hard, if you want to grasp the overall performance of the program, this Benchmark debugging tool cannot meet your needs, next, we will discuss how to install and use the PHP performance debugging tool xDebuger.
(PHP 3, PHP 4, PHP 5)
Microtime -- returns the current Unix timestamp and microseconds.
Mixed microtime ([bool get_as_float])
Microtime () current Unix timestamp and number of microseconds. This function is only available in the operating system that supports the gettimeofday () system call.
If no optional parameter is required, this function returns a string in the format of "msec sec", where sec is the current number of seconds since the Unix epoch (0:00:00 January 1, 1970 GMT, msec is in microseconds. The two parts of the string are returned in seconds.
If the get_as_float parameter is given and its value is equivalent to TRUE, microtime () returns a floating point number.
Note: The get_as_float parameter is newly added to PHP 5.0.0.
PHP Benchmark/Timer Class
Benchmark and Optimize PHP Script Speed
Bytes. To do what you want, you must first sharpen your skills! How to install PEAR and Benchma...