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

Extending the use of the xdebug_time_index() function - 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



In the section that you just read, I explained how to use the “xdebug_time_index()” function, to create a simple procedural timing script. However, it’s also feasible to take advantage of the intrinsic capabilities of this function to build a timer class.

Want to see how this class can be built in a few easy steps? Examine the following code sample, which defines a primitive “Timer” class that obviously uses the “xdebug_time_index()” function as its workhorse. Here it is:

class Timer{

public function __construct(){}

public function getTime(){

return xdebug_time_index();



Indeed, the above “Timer” class doesn’t bear any further discussion. It only implements a single method called “getTime(),” which behaves as a wrapper for the “xdebug_time_index()” function. That’s all.

It would, however, be pretty interesting to see how this class can be used for timing a simple application. Thus, below I coded a final hands-on example that utilizes the previous timing class for calculating the total execution time of a basic script. Here it is:

$timer=new Timer();

echo 'Starting time :'.$timer->getTime().'<br />';




echo 'Total script execution time :'.$timer->getTime();

/* displays the following

Starting time :0.0012168884277344

Total script execution time :5.9927868843079


Here you have it. Now that you’ve seen for yourself how simple it is to build a timer class using the “xdebug_time_index()” function, hopefully this will fire up your own creativity, and you’ll start building your own benchmarking scripts.

Final thoughts

In this sixth episode of the series, I walked you through using the “xdebug_time_index()” function that comes with the X-debug extension, to perform basic benchmarking on several PHP scripts. Undeniably, the utilization of this function is pretty intuitive, so in theory you shouldn’t have major problems using it for timing your own PHP programs.

However, this series still has a final installment, in which you’ll learn how to employ another handy function of the X-debug library. It's called “xdebug_get_function_stack(),” and it will be utilized for exploring the stack of function calls generated by the PHP engine during the execution of a script.

Now that you’ve been warned about the subject of the final article of this series, you won’t want to miss it!

>>> 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: