<?php
class Timer {
var $_marker = array();
function __construct () {
// Init class Timer
}
function Timer (){
// Init class Timer
}
// Maker timer, and if stop = true get time and stop!
public function Marker ( $name , $stop = false){
if($stop){
if(!isset($this->_marker[$name])){
return false;
}
$this->_marker[$name][1] = microtime();
return $this->getTime($name);
}
$this->_marker[$name] = array(microtime());
return true;
}
// get total time and stop timer
public function getTime( $name, $roundTo = 5 ) {
// If not exists maker return 0
// It's a good one ?
if(!isset($this->_marker[$name])){
return "0";
}
// Some fixed added
if(!isset($this->marker[$name][1])){
$this->_marker[$name][1] = microtime();
}
// Mili + seconds
list($usec, $sec) = explode(" ", $this->_marker[$name][0]);
list($usecF, $secF) = explode(" ", $this->_marker[$name][1]);
// plus
$be = ((float)$usec + (float)$sec);
$fi = ((float)$usecF + (float)$secF);
// return total time
return round($fi-$be,$roundTo);
}
}
?>
|