PHP Classes
elePHPant
Icontem

File: class.timestamps.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of runcore  >  Time to generate a page or blocks  >  class.timestamps.php  >  Download  
File: class.timestamps.php
Role: Class source
Content type: text/plain
Description: class source
Class: Time to generate a page or blocks
Measure the time that takes to execute a script
Author: By
Last change:
Date: 10 years ago
Size: 1,382 bytes
 

Contents

Class file image Download
<?php
/*
    TimeStamps class
    06/09/2005
    autor: runcore <runcore@tusur.ru>
*/

class timeStamps {

    var
$tArr = array(); // array with timestamps
   
var $i = 0; // index of tArr

   
function timeStamps($comment = '') {
       
$this->addTime($comment);
    }

    function
addTime($comment = '') {
       
$this->tArr[$this->i][0] = $this->getMicrotime();
       
$this->tArr[$this->i][1] = $comment.(empty($comment) ? 'timestamp'.$this->i : '' );
       
$this->i++;
    }

    function
getMicrotime() {
        list(
$usec, $sec) = explode(' ', microtime());
        return ((float)
$usec + (float)$sec);
    }

    function
getTimesArraySize() {
        if (
sizeof($this->tArr) < 2) $this->addTime('last timestamp');
        return (
$this->tArr[sizeof($this->tArr)-1][0] - $this->tArr[0][0] );
    }

    function
getTimesArray() {
       
$oArr = array();
        for (
$x=1; $x<sizeof($this->tArr); $x++) {
           
$oArr[$x][0] = $this->tArr[$x][0] - $this->tArr[$x-1][0];
           
$oArr[$x][1] = $this->tArr[$x-1][1].' ... '.$this->tArr[$x][1];
        }
        return
$oArr;
    }

    function
printTimesTable() {
       
$oArr = $this->getTimesArray();
        echo
'<table border="1"><tr bgcolor="#cccccc"><td><b>length</b></td><td><b>labels</b></td></tr>';
        for (
$x=1; $x<sizeof($this->tArr); $x++) {
            echo
'<tr>
            <td>'
.number_format($oArr[$x][0], 14, '.', ' ').'</td>
            <td>'
.$oArr[$x][1].'</td>
            </tr>'
;
        }
        echo
'</table>';
    }

}

?>