Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Sharpen Your Code with Benchmarking in PHP : Page 2

Discover how to optimize your PHP applications using these straightforward yet powerful benchmarking techniques.


advertisement
Benchmarking Output
Both the iterative and recursive Fibonacci programs output the results in two forms: a formatted table, and as a raw associative array.

The formatted table results show each marker name, the elapsed time when that marker was reached (time index), the time required to reach that marker from the previous marker (ex time), and the percentage of the total time required to reach that marker from the previous marker (%).

The iterative result is:

  Time Index Ex Time Percentage
Start 1209633208.32539500 - 0.00%
fibonacci0 1209633208.32546500 0.000070 22.88%
fibonacci1 1209633208.32549400 0.000029 9.48%
fibonacci2 1209633208.32551600 0.000022 7.19%
fibonacci3 1209633208.32553900 0.000023 7.52%
fibonacci4 1209633208.32556200 0.000023 7.52%
fibonacci5 1209633208.32558600 0.000024 7.84%
fibonacci6 1209633208.32560800 0.000022 7.19%
fibonacci7 1209633208.32563100 0.000023 7.52%
fibonacci8 1209633208.32565600 0.000025 8.17%
fibonacci9 1209633208.32567800 0.000022 7.19%
Stop 1209633208.32570100 0.000023 7.52%
Total - 0.000306 100.00%

The associative array contains the same information in a machine-usable form.

Array ( [name] => fibonacci0 [time] => 1209633208.32546500 [diff] => 0.000070 [total] => 0.000070 ) Array ( [name] => fibonacci1 [time] => 1209633208.32549400 [diff] => 0.000029 [total] => 0.000099 ) Array ( [name] => fibonacci2 [time] => 1209633208.32551600 [diff] => 0.000022 [total] => 0.000121 )

The recursive result is:

  Time Index Ex Time Percentage
Start 1209633188.10306000 - 0.00%
fibonacci0 1209633188.10322500 0.000165 7.83%
fibonacci1 1209633188.10330500 0.000080 3.80%
fibonacci2 1209633188.10335800 0.000053 2.52%
fibonacci3 1209633188.10343000 0.000072 3.42%
fibonacci4 1209633188.10350000 0.000070 3.32%
fibonacci5 1209633188.10359200 0.000092 4.37%
fibonacci6 1209633188.10371600 0.000124 5.89%
fibonacci7 1209633188.10388300 0.000167 7.93%
fibonacci8 1209633188.10415100 0.000268 12.72%
fibonacci9 1209633188.10455300 0.000402 19.08%
Stop 1209633188.10516700 0.000614 29.14%
Total - 0.002107 100.00%

Again, the associative array contains the same information in a machine-usable form.

Array ( [name] => fibonacci0 [time] => 1209633188.10322500 [diff] => 0.000165 [total] => 0.000165 ) Array ( [name] => fibonacci1 [time] => 1209633188.10330500 [diff] => 0.000080 [total] => 0.000245 ) Array ( [name] => fibonacci2 [time] => 1209633188.10335800 [diff] => 0.000053 [total] => 0.000298 )

As you can see, the timer provides fine-grained results that you can control using the marker capabilities. In most cases, however, you are likely to be less interested in benchmarking individual lines of code and more interested in benchmarking distinct functions, particularly when you can do that without modifying the function code itself. For that, you use the Benchmark_Iterate class.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap