Zend - The PHP Company




Utilities

Add Code


Timemeter  

Type: class
Added by: Shurup
Entered: 31/10/2001
Last modified: 01/11/2000
Rating: - (fewer than 3 votes)
Views: 4467
This class is very useful to measure performance time within your PHP script. It measures a script runtime between two checkpoints (start() and finish()) For example: Using this class you can select most effizient algorythms, methodes or technologies.


<?php
//save this class in timemeter.php

#################################
#                               #
#   Alex Zwitbaum, 2001         #
#                               #
#   unit for measure runtime    #
#                               #
#################################

class timemeter {
    var 
$starttime;
    function 
start() {
        
$t=microtime(); 
        
$time_b explode (" "$t); 
        
$this->starttime doubleval($time_b[0])+$time_b[1];
    }
 
    function 
finish() {
        
$t=microtime(); 
        
$time_e explode (" "$t); 
        
$endtime doubleval($time_e[0])+$time_e[1];
        echo 
"<br><br>Dauer: <b>",sprintf ("%01.4f"$endtime-$this->starttime),"</b> s ";
    }    
}
?>


Usage Example


<?
include("timemeter.php");
$meter = new timemeter;

//... your code ...
//...

$meter->start(); //Start

//... code to measure performance of ...
//for example
phpinfo();

$meter->finish();
?>


Rate This Script





Search



This Category All Categories