PHP program accelerated exploration-script execution speed test_php tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.