PHP Program accelerated exploration of script Execution Speed test _php tutorial

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

  • 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.