Test the script execution speed of PHP program accelerated exploration and read the script execution speed test of PHP program accelerated exploration. as mentioned above, we can only optimize the code that affects the speed. The Benchmark_Timer class and Benchmark_Iterate class in the benchmark package of PEAR can be used to conveniently test the speed of script execution. (About PEAR's security "> <LINKhr
As mentioned above, we can only optimize the code that affects the speed. The Benchmark_Timer class and Benchmark_Iterate class in the benchmark package of PEAR can be used to conveniently test the speed of script execution. (For installation and configuration of PEAR, see relevant information ).
First, use the Benchmark_Iterate class to test the execution time of a function or method of a class in the program.
Benchmark1.php
Require_once ('benchmark/Iterate. php ');
$ Benchmark = new Benchmark_Iterate ();
$ Benchmark-> run (10, 'myfunction', 'test ');
$ Result = $ benchmark-> get ();
Echo"
"; Print_r ($ result); echo"
";
Exit;
Function myFunction ($ var ){
// Do something
Echo 'hello ';
}
?>
Create the benchmark Iterate object $ benchmark, which is used to execute the myFunction for 10 times.
The $ argument variable is passed to myFunction each time. the analysis results run multiple times are saved to $ result, and then obtained using the get () method of the benchmark object. This result is output to the screen using print_r. The following results are usually output:
Hello
Array
(
[1] => 0.000427 [2] => 0.000079 [3] => 0.000072 [4] => 0.000071 [5] => 0.000076 [6] => 0.000070 [7] => 0.000073 [8] => 0.000070 [9] => 0.000074 [10] => 0.000072 [mean] => 0.000108 [iterations] => 10)
Every execution of myFunction, the benchmark object tracks the execution time. And calculates the average execution time (the line [mean ). By running the target function multiple times, you can obtain the average running time of the function.
In actual tests, the number of functions should be at least 1000 times, so that objective results can be obtained.