Home arrow PHP arrow Page 3 - Benchmarking with the Xdebug Extension

Benchmarking PHP applications with the X-debug extension - PHP

Welcome to the sixth installment of a series that covers debugging in PHP with the Xdebug extension. Comprised of seven approachable tutorials, this series gets you started using the set of functions provided by this helpful library, so you can begin debugging your own PHP applications with an excellent level of control.

TABLE OF CONTENTS:
  1. Benchmarking with the Xdebug Extension
  2. Review: tracking program flow with the Xdebug extension
  3. Benchmarking PHP applications with the X-debug extension
  4. Extending the use of the xdebug_time_index() function
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
March 09, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

As you may guess, any decent PHP debugging library must have the capability of benchmarking programs with relative ease, and certainly Xdebug isn’t an exception. The library in question comes equipped with a handy function called “xdebug_time_index(),” which can be used for timing PHP scripts with extreme simplicity.

To demonstrate this function, I’m going to start coding a basic example, which will use it within a typical “for” loop. Here’s the corresponding code sample; have a look at it, please:


echo 'Starting time : '.xdebug_time_index().'<br />';

for($i=0;$i<=3;$i++){

// do nothing

sleep(1);

}

echo 'Total script execution time : '.xdebug_time_index();


/* displays the following


Starting time : 0.001168966293335

Total script execution time : 3.9993019104004

*/


If you analyze the above code sample, you’ll realize how simple it is to benchmark a specified PHP script using the aforementioned “xdebug_time_index()” function. As shown above, the function has been called twice, that is before the “for” statement starts its iteration, and at the end of the script, to display its total execution time.

Of course, if you’re anything like me, then you may want to see how the flexibility offered by the “xdebug_time_index()” function can be exploited to create an object-oriented timing application with extreme ease.

With that idea in mind, the last section of this article will be focused on explaining how to build a basic timer class, which will use internally the previous “xdebug_time_index()” function for benchmarking PHP scripts.

This brand new timer class will be developed in the following segment, so jump ahead and read the new few lines. I’ll be there, waiting for you.



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap

Dev Shed Tutorial Topics: