Test script execution speed for 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 code that affects the speed. as mentioned above, only the code that affects the speed can be optimized. 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 (as the mainstream development language)
Require_once (Benchmark/Iterate. php (as the mainstream development language ));
$ 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.
Bytes. The Benchmark_Timer class and Benchmark_Iterate class in the benchmark package of PEAR can be conveniently used for testing...