PHP
  Home arrow PHP arrow Page 3 - Benchmarking Applications with PHP
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
PHP

Benchmarking Applications with PHP
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-04-23

    Table of Contents:
  • Benchmarking Applications with PHP
  • Using the microtime() built-in PHP function
  • Simplifying the use of the microtime() function
  • Using an object-oriented approach for benchmarking scripts
  • Defining a wrapper method for the PHP 5 microtime() function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Dell PowerEdge Servers

    Benchmarking Applications with PHP - Simplifying the use of the microtime() function
    (Page 3 of 5 )

    In the previous section, I mentioned that PHP 5 offered a slightly modified version of the native “microtime()” function, since there’s no need to create a custom function to obtain a float number from it. But you have to make sure to call this function with the “get_as_float” parameter. Then it will neatly return the corresponding timestamp as a float value.

    In order to illustrate the usage of the “microtime()” function with PHP 5, I created a basic example that shows how to use this function for benchmarking purposes. Have a look a the following code sample:


    // example using 'microtime()' function with PHP 5

    $startTime=microtime(true);

    // do nothing for a while

    usleep(100);

    $endTime=microtime(true);

    $totalTime=$endTime-$startTime;

    echo 'Time spent in doing nothing was '.$totalTime.' seconds';


    In this case, the above script simply calls the “microtime()” function with the “get_as_float” parameter set to true. Lastly, it displays the elapsed time as a float number. Of course, this condition is clearly demonstrated by the below output:

    Time spent in doing nothing was 0.00532197952271 seconds

    In addition to the example that you learned before, it’s possible to define a simple wrapper for the “microtime()” function in PHP 5 and create the following script:


    // define 'getMicrotime()'function - PHP 5

    function getMicrotime(){

    return microtime(true);

    }

    $startTime=getMicrotime();

    // do nothing for a while

    usleep(100);

    $endTime=getMicrotime();

    $totalTime=$endTime-$startTime;

    echo 'Time spent in doing nothing was '.$totalTime.' seconds';

    /*

    displays the following:

    Time spent in doing nothing was 0.00789403915405 seconds

    */


    As you can see, creating simple and effective timing scripts is something that can easily be done with PHP 4 or PHP 5, and they can be used as decent benchmarking approaches too.

    So far, I demonstrated the capacity offered by PHP 4 and PHP 5 respectively for developing simple and efficient timing functions. However, it’s possible (and even desirable) to go one step further and develop an object-oriented timing approach that can be used for benchmarking purposes as well.

    In this case, I’m simply talking about creating a timer class that can be utilized, obviously, to time several scripts and applications together. Therefore, I suggest you read the following section, where I’ll explain how to build these specific classes.

    More PHP Articles
    More By Alejandro Gervasio


       · One exciting thing that you want to do with PHP, is benchmarking a particular...
       · The technique described (using microtime()) has limitations in that you must add the...
       · Thank you for commenting on my PHP article and for mentioning the xdebug extension....
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway