WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : A time measuring and performance benchmarking class
Categories : PHP, PHP Classes, Testing, Debugging, Date Time Click here to Update Your Picture
Ioannis Cherouvim
Date : Jun 21st 2005
Grade : 2 of 5 (graded 5 times)
Viewed : 4974
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Ioannis Cherouvim
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php

//***************************************************************
//** title  : A time measuring and performance benchmarking class.
//**
//** story  : Sometimes you need to fine tune your php application
//**          or just examine which parts of your code need more
//**          time to be executed. This class will help you measure
//**          execution times of any block of code you want.
//**          You can even stick it in a loop to check whether its
//**          iterations require even amounts of cpu time to be
//**          executed, in order to spot possible anomalies in your
//**          application's execution.
//**
//** author : Ioannis Cherouvim
//** e-mail : morales@hack.gr
//** date   : 2005-06-21
//*******************************************************

   
class Perf {
        var
$init;
        var
$count;
        var
$temp;

       
//instantiate reader
       
function Perf() {
           
$this->init = $this->getmicrotime();
        }

       
//start the clock
       
function start() {
           
$this->temp = $this->getmicrotime();
        }
       
       
//stop the clock
       
function stop() {
           
$this->count[] = $this->getmicrotime() - $this->temp;
        }

       
//show results, with a boolean parameter
       
function printResults($analytical) {
            echo
"Total execution time " . $this->getSize($this->getmicrotime() - $this->init)."<br/>";
           
$count = count($this->count);
            if (
$count==0) return;
           
$min=$this->count[0];
           
$max=$this->count[0];
           
$total=$mini=$maxi=0;
            for(
$i=0; $i<$count; $i++) {
               
$value = $this->count[$i];
                if (
$value<$min) {$min = $value; $mini = $i;}
                if (
$value>$max) {$max = $value; $maxi = $i;}
               
$total+=$value;
                if (
$analytical) echo "•iteration #" . ($i+1) . " " . $this->getSize($this->count[$i])."<br/>";
            }
            echo
"Total iterations " . $count . "<br/>";
            echo
"Average iteration time " . $this->getSize($total/$count)."<br/>";
            echo
"Min iteration time " . $this->getSize($min) . " on iteration #" . ($mini+1) . "<br/>";
            echo
"Max iteration time " . $this->getSize($max) . " on iteration #" . ($maxi+1) . "<br/>";
        }

       
//private method to convert milliseconds into something more
        //humanly readable
       
function getSize($size) {
           
$times = array("msecs", "secs", "mins", "hours", "days", "months", "years");
           
$divs = array(1000, 60, 60, 24, 30, 12);
           
$i = 0;
            while (
$i<count($divs) && $size >= $divs[$i]) {
               
$size/=$divs[$i];
               
$i++;
            }
            return
round($size, 4)." ".$times[$i];
        }

       
//private method to get the time
       
function getmicrotime(){
            list(
$usec, $sec) = explode(" ",microtime());
            return ((float)
$usec + (float)$sec)*1000;
        }

    }

   
//****************************************************
    //** An example use of this class
    //****************************************************
   
$perf = new Perf();
   
    for(
$i=0;$i<10; $i++){
       
//start counting
       
$perf->start();
        echo
"..$i blah blah..".rand();
       
$x=rand();
        if (
$i==3) {
            for(
$x=1;$x<12123;$x++){
               
$y=cos(432);
            }
        }
       
$x=$x*rand();
       
//stop counting
       
$perf->stop();
    }
    echo
"<hr>";
   
$perf->printResults(true);

?>



A Timing Class
Categories : PHP, PHP Classes, Date Time
The class to check load time of your script VERY usefull for relatively slow applications, but not only..
Categories : PHP, PHP Classes, Debugging
pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes
Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example.
Categories : PHP, Date Time, PHP Classes, Calendar
Open and Close your website in fixed times .
Categories : PHP, PHP Classes, Cron, Date Time
A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function.
Categories : PHP, PHP Classes, Calendar, Date Time
Validator - A PHP class that can can be used for validating Email IDs and Dates
Categories : PHP, PHP Classes, Data Validation, Email, Date Time
Bs_StopWatch is a class to measure time intervals in microseconds.
Categories : PHP, Date Time, PHP Classes
A Custom Error Handling And Debugging Class
Categories : PHP, PHP Classes, Debugging, Errors and Logging
Customizable Calendar Class
Categories : HTML and PHP, Date Time, PHP, PHP Classes, Calendar
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
a class that uses microtime() to provide easy calculation of elapsed times
Categories : Date Time, PHP, PHP Classes
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
PHP Paypal IPN Integration Class v1.0.0
Categories : PHP, PHP Classes, Payment Gateways
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics