PHP Classes

File: cronoClass

Recommend this page to a friend!
  Classes of djdomix   All in one date class   cronoClass   Download  
File: cronoClass
Role: Example script
Content type: text/plain
Description: Cronometro
Class: All in one date class
Perform many operations with times and dates
Author: By
Last change:
Date: 18 years ago
Size: 2,254 bytes
 

Contents

Class file image Download
<?

require_once "dateClass.php";

class
cronoClass extends dateClass
{
    private
$_cronoStart = array();
    private
$_cronoStop = array();
    private
$_milliStart = array();
    private
$_milliStop = array();
    private
$_precision_milli = false;
   
    public function
set_precision_milli($precision_milli = false)
    {
        if (!
is_bool($precision_milli))
            throw new
Exception("$precision_milli is not valid parameter",0);
       
$this -> _precision_milli = $precision_milli;
    }
    public function
start($label = false)
    {
        if (
$this -> _precision_milli)
        {
           
$this -> _milliStart[$label] = $this -> get_Milliseconds();
           
$this -> _cronoStart[$label] = time();
            return;
        }
        if (
$label === false)
            throw new
Exception("You must define a crono label",0);
       
$this -> _cronoStart[$label] = $this -> get_Time(true);
       
    }
    public function
stop($label = false)
    {
       
        if (
$this -> _precision_milli)
        {
           
$this -> _milliStop[$label] = $this -> get_Milliseconds();
           
$this -> _cronoStop[$label] = time();
            return;
        }
       
        if (
$label === false)
            throw new
Exception("You must define a crono label",0);
        if (!isset(
$this -> _cronoStart[$label]))
            throw new
Exception("The label $label not exsist",0);
       
$this -> _cronoStop[$label] = $this -> get_Time(true);
    }
    public function
get_diff_seconds($label = false)
    {
       
$value1 = $this -> _cronoStop[$label] + $this -> _milliStop[$label];
       
$value2 = $this -> _cronoStart[$label] + $this -> _milliStart[$label];
        return
$value1 - $value2;
    }
    public function
get_diff_media()
    {
       
$keys = array_keys($this -> _milliStart);
        for (
$i = 0;$i< count($keys);$i++)
        {
           
$tot += $this -> get_diff_seconds($keys[$i]);
           
        }
        return
$tot / count($keys);
    }
}


$cronometro = new cronoClass();
$cronometro -> set_precision_milli(true);
$i = 0;
$test = new dateClass();
for (;
$i< 1000;$i++)
{
    if (
$i == 0) continue;
$cronometro -> start("test$i");

//sezione di test


try
{
   
$test -> set_Day("04");
   
//$test -> set_Month("12");
    //$test -> set_Year("99");
    //print_R($test -> toSource());
   
}
catch (
Exception $e)
{
   
$data = $e -> getTrace();
   
    echo
$e -> getMessage() . " - generated in function " . $data[0]["function"];
   
}


$cronometro -> stop("test$i");
}

echo
"<hr>" . $cronometro -> get_diff_media();


?>