PHP Code:
<?php
class Benchmark{
private $ElapsedTime = Array();
function __destruct(){
unset($ElapsedTime);
}
public function Mark($Handle){
$this->ElapsedTime[$Handle] = (float) microtime(true);
}
public function Elapsed($Handle_Start, $Handle_Stop, $Decimals=false){
$ElapsedTime = 0;
if(isset($this->ElapsedTime[$Handle_Start]) && $this->ElapsedTime[$Handle_Start] > 0 && isset($this->ElapsedTime[$Handle_Stop]) && $this->ElapsedTime[$Handle_Stop] > 0){
if($Decimals !== false){
$ElapsedTime = round(($this->ElapsedTime[$Handle_Stop] - $this->ElapsedTime[$Handle_Start]), $Decimals);
}else{
$ElapsedTime = abs($this->ElapsedTime[$Handle_Stop] - $this->ElapsedTime[$Handle_Start]);
}
}
return $ElapsedTime;
}
}
?>
Due to the fact many people may not understand it, it is rather simple here is an example;
PHP Code:
<?php
$Benchmark = new Benchmark();
$Benchmark->Mark('start');
usleep(1000000);
$Benchmark->Mark('stop');
echo $Benchmark->Elapsed('start', 'stop');
?>
Results 1 to 5 of 5
Thread: [PHP] Benchmarking Class
Threaded View
- 20 Nov. 2009 02:14am #1
- Age
- 30
- Join Date
- Nov. 2009
- Location
- Anaheim, California
- Posts
- 1,065
- Reputation
- 99
- LCash
- 500.00
[PHP] Benchmarking Class