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.

  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



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 />';


// do nothing



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
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- 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...

Developer Shed Affiliates


Dev Shed Tutorial Topics: