All pastes #905177 Raw Edit

Unbenannt

public text v1 · immutable
·published 2008-02-15 16:43 UTC
rendered paste body
<?php

class PerfTest
{
	private $NextPoint;
	private $LastTime;
	private $PointName;
	
	public $ResArray;
	public $StartTime;
	public $EndTime;
	public $Decimals = 7;
	public $MaxTime = 0;
	
	public function SetPoint($PointName = "")
	{
		if($PointName == "")
		{
			$PointName = $this->GetNextPoint();
		}
		
		if(isset($this->ResArray[$PointName]))
		{
		  trigger_error("Point \"".$PointName."\" already set! Overwriting...", E_USER_NOTICE);
		}
    				
		$this->ResArray[$PointName] = microtime(true);
		
		if(!isset($this->StartTime))
		{
			$this->StartTime = $this->ResArray[$PointName];
			$this->LastTime = $this->StartTime;
		}
	}
	
	public function PrintRes()
	{
		$this->EndTime = microtime(true);
		echo "<pre>";
		echo "| FLS Performance Test  v1.0               |\n";
		echo "--------------------------------------------\n";
		echo "Name\t\t-> Absolute\t-> Relative\n";
		
		foreach($this->ResArray as $key => $value)
		{	
			$relative = number_format(($value-$this->StartTime), $this->Decimals);
			$absolute = number_format(($value-$this->LastTime), $this->Decimals);
			$key = substr(str_pad($key, 16), 0, 15);
			echo $key."\t-> ".$relative."\t-> ".$absolute."\n";
			$this->LastTime = $value;
		}
				
    echo "--------------------------------------------\n";
		echo "| (c) Matthias Anton 2008                  |";
		echo "</pre>";
	}
	
	private function GetNextPoint()
	{
		$this->NextPoint = count($this->ResArray)+1;
		return "Point ".$this->NextPoint;
	}
}

/*
$perf = new PerfTest;
$perf->SetPoint("First");
sleep(1);
$perf->SetPoint("Test1");
sleep(1);
$perf->SetPoint();
$perf->SetPoint();

$perf->PrintRes();
*/

?>