PHP
  Home arrow PHP arrow Page 2 - Benchmarking with the Xdebug Extension
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Forums Sitemap 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Benchmarking with the Xdebug Extension
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 1
    2009-03-09


    Table of Contents:
  • Benchmarking with the Xdebug Extension
  • Review: tracking program flow with the Xdebug extension
  • Benchmarking PHP applications with the X-debug extension
  • Extending the use of the xdebug_time_index() function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Benchmarking with the Xdebug Extension - Review: tracking program flow with the Xdebug extension
    (Page 2 of 4 )

    If you didn’t have the chance to learn how to use the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions for keeping track of the sequence of lines executed by a PHP application, then you’re in luck; here’s an example created in the preceding article of this series, which demonstrates how to utilize these functions along with a simple PHP class.

    Take a look at the corresponding code sample, please:


    class User{

    private $firstName;

    private $lastName;

    private $email;

    public function __construct($firstName,$lastName,$email){

    if(!$firstName){

    throw new Exception('Invalid parameter First Name.');

    }

    if(!$lastName){

    throw new Exception('Invalid parameter Last Name.');

    }

    if(!$email){

    throw new Exception('Invalid parameter Email.');

    }

    $this->firstName=$firstName;

    $this->lastName=$lastName;

    $this->email=$email;

    }

    // get first name

    public function getFirstName(){

    return $this->firstName;

    }

    // get last name

    public function getLastName(){

    return $this->lastName;

    }

    // get email

    public function getEmail(){

    return $this->email;

    }

    }


    xdebug_start_code_coverage();

    $user=new User('John','Doe','john@domain.com');

    if(rand(1,10)<5){

    echo 'First Name :'.$user->getFirstName().'<br />';

    echo 'Last Name :'.$user->getLastName().'<br />';

    }

    else{

    echo 'Email :'.$user->getEmail().'<br />';

    }

    var_dump(xdebug_get_code_coverage());


    /* displays the following when 'rand()' function returns a value < 5


    First Name :John

    Last Name :Doe


    array

    '/path/to/example/program_flow_debug.php' =>

    array

    8 => int 1

    11 => int 1

    14 => int 1

    17 => int 1

    18 => int 1

    19 => int 1

    20 => int 1

    23 => int 1

    36 => int 1

    37 => int 1

    38 => int 1

    39 => int 1

    40 => int 1

    44 => int 1


    // displays the following when the 'rand()' function returns a value > 5


    Email :john@domain.com


    array

    '/path/to/example/program_flow_debug.php' =>

    array

    8 => int 1

    11 => int 1

    14 => int 1

    17 => int 1

    18 => int 1

    19 => int 1

    20 => int 1

    31 => int 1

    36 => int 1

    37 => int 1

    42 => int 1

    44 => int 1


    */


    As illustrated by the above hands-on example, the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions can be very useful when it comes to finding out the sequence of lines executed by a PHP script.

    In this specific case, this pair of complementary functions is utilized in conjunction with a basic class and a simple conditional “if” statement, with the purpose of showing how the two blocks of code that compose the prior script are called by the PHP engine. Not too difficult to grasp, right?

    Well, at this point I should assume that you’re pretty familiar with using the “xdebug_start_code_coverage()” and “xdebug_get_code_coverage()” functions to control the flow of a specified PHP program. Therefore, it’s time to continue exploring other functions of the library.

    As I stated in the beginning, this extension also offers a function called “xdebug_time_index().” As its name suggests, it can be used for timing PHP scripts with minor hassles. Therefore, in the section to come I’ll be explaining how to use this function for benchmarking purposes.

    This topic will be discussed in the next few lines, so click on the link that appears below and keep reading.



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

       

    PHP ARTICLES

    - Getting More Info on Reflected Properties wi...
    - Implementing the Iterator SPL Interface
    - Building a Data Access Layer for the Data Ma...
    - Building a Singleton Database with Restricti...
    - Working with Reflected Properties with the R...
    - The Iterator, Countable and ArrayAccess SPL ...
    - Implementing the Data Mapper Design Pattern ...
    - Defining an Abstract Class with Restrictive ...
    - The Reflection API: Working with Reflected M...
    - Using Restrictive Constructors in PHP 5
    - Getting Information on a Reflected Class wit...
    - Introducing the Reflection API in PHP 5
    - Swift Mailer's Batchsend Method and Other Fe...
    - Embedding Attachments into Email Messages wi...
    - Dynamically Attaching Files with Swift Mailer


    Code Analysis Tools
    Enterprise code analysis tools that deliver quality and reliable code



    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 10 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek