PEAR Articles
  Home arrow PEAR Articles arrow Page 3 - Introduction to PEAR
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
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? 
PEAR ARTICLES

Introduction to PEAR
By: bluephoenix
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 8
    2003-09-30

    Table of Contents:
  • Introduction to PEAR
  • PEAR Installation
  • The Benchmark Package
  • Conclusion

  • 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


    Introduction to PEAR - The Benchmark Package


    (Page 3 of 4 )

    The Benchmark package is now installed and ready to go. The desired extensions are made available to our script by using the require_once statement to include the appropriate file.

    <?php
    require_once "Benchmark/Timer.php";
    ?>

    If PHP complains it was unable find the file, you may need to modify your php.ini file's include_path directive. Or, you can temporarily append the directory to the include path for the duration of the script by using the ini_set() function.

    <?php
    ini_set
    ("include_path"
            
    ini_get("include_path") . "/usr/local/lib/php");
    require_once 
    "Benchmark/Timer.php";
    ?>

    The Benchmark module times the execution of a script and displays the results in the form of a table.

    <?php
    require_once "Benchmark/Timer.php";

    $t = new Benchmark_Timer();
    $t-&gt;start();
    echo 
    "Hello, World! &lt;br /&gt;";
    $t-&gt;stop();

    echo 
    "&lt;pre&gt;" $t-&gt;display() . "&lt;/pre&gt;";
    ?>

    A new timer object is created with new Benchmark_Timer and is made accessible by assigning it to the variable $t. The object can then be manipulated by the methods start, stop and display. Intuitively, start will start the timer, stop will stop the timer and display will output the results table.

    The output of the above script would resemble the following:

    Hello World!
    -------------------------------------------------------------
    marker    time index            ex time               perct
    -------------------------------------------------------------
    Start     1064782761.34820600   -                       0.00%
    -------------------------------------------------------------
    Stop      1064782761.34845500   0.00024890899658203   100.00%
    -------------------------------------------------------------
    total     -                     0.00024890899658203   100.00%
    -------------------------------------------------------------

    You may even set markers throughout your code to compare the execution time of various sections. This is done with the setMarker method which accepts a string to identify the marker.

    <?php
    require_once "Benchmark/Timer.php";

    $t = new Benchmark_Timer();
    $t-&gt;start();
    echo 
    "Hello, World! &lt;br /&gt;";

    $t-&gt;setMarker("Section One");
    for (
    $count 0$count &lt100$count++) {
         echo 
    $count+" ";
    }
    echo 
    "&lt;br /&gt;";

    $t-&gt;setMarker("Section Two");
    echo 
    "Good Bye! &lt;br /&gt;";

    $t-&gt;stop();

    echo 
    "&lt;pre&gt;" $t-&gt;display() . "&lt;/pre&gt;";
    ?>

    The markers create new entries in the final results table.

    Hello, World!
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
    27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
    50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
    96 97 98 99 100
    Good Bye!
    -------------------------------------------------------------------
    marker          time index            ex time               perct
    -------------------------------------------------------------------
    Start           1064783416.23436900   -                       0.00%
    -------------------------------------------------------------------
    Section One     1064783416.23462200   0.00025296211242676     6.04%
    -------------------------------------------------------------------
    Section Two     1064783416.23846400   0.0038419961929321     91.80%
    -------------------------------------------------------------------
    Stop            1064783416.23855400   9.000301361084E-05      2.15%
    -------------------------------------------------------------------
    total           -                     0.0041849613189697    100.00%
    -------------------------------------------------------------------

    The benchmarking utility provided through PEAR is easy to implement and is a useful tool to examine the efficiency of your scripts... but it's also only one of many useful PEAR packages. To date over 200 packages are available through the PEAR Package Manager and are organized in various repositories.

    More PEAR Articles Articles
    More By bluephoenix


     

    PEAR ARTICLES ARTICLES

    - Using XML_RPC2 with PEAR
    - Using Web Service APIs (Amazon and Yahoo!) w...
    - Database Abstraction with MDB2 from PEAR
    - The PEAR Package Tour: PEAR Basics
    - Caching with PEAR::Cache
    - Introduction to PEAR
    - The PEAR ITX Templating System






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