As mentioned earlier, it is possible to optimize only if we find code that affects speed. The Benchmark_timer class and Benchmark_iterate class in the Pear benchmark package can be used to easily test the speed of script execution. (For pear installation and configuration, please check the relevant information yourself).
First, use the Benchmark_iterate class to test the execution time of a method of a function or class in a program.
Benchmark1.php (as the current mainstream development language)
Require_once (benchmark/iterate.php (as the current mainstream development language));
$benchmark = new Benchmark_iterate ();
$benchmark->run (myfunction,test);
$result = $benchmark->get ();
echo "
"; Print_r ($result); echo "
";
Exit
function MyFunction ($var) {
Do something
Echo Hello;
}
? >
Establishes the benchmark iterate object $benchmark, which is used to execute the MyFunction function 10 times.
$argument variables are passed to myfunction each time. The results of the multiple run analysis are stored in $result and then obtained using the Get () method of the benchmark object. The result is output to the screen with Print_r (). This usually outputs the result:
Hello-Hello-Hello-Hello-Hello-Hello-Hello-Hello-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.0 00070 [9] => 0.000074 [ten] => 0.000072 [mean] => 0.000108 [iterations] => 10)
MyFunction each execution, the benchmark object tracks the execution time. And the average execution time is calculated ([mean] that line). By running the target function multiple times, you can get the average run time of the function.
In the actual test, the number of functions should be at least 1000 times, so that more objective results can be obtained.
http://www.bkjia.com/PHPjc/508702.html www.bkjia.com true http://www.bkjia.com/PHPjc/508702.html techarticle as mentioned earlier, it is possible to optimize only if we find code that affects speed. Pear Benchmark package of Benchmark_timer class and Benchmark_iterate class, can be used to easily test ...