00001 <?php 00016 class Benchmark 00017 { 00023 public function __construct() 00024 { 00025 date_default_timezone_set('Europe/Stockholm'); 00026 $this->_startAt = NULL; 00027 $this->_stopAt = NULL; 00028 } 00029 00033 public function start() 00034 { 00035 $this->_stopAt = NULL; 00036 $this->_startAt = time(); 00037 } 00038 00045 public function stop() 00046 { 00047 $this->_stopAt = time(); 00048 return $this->_stopAt - $this->_startAt; 00049 } 00050 00056 public function getStartTime() 00057 { 00058 return date('dMY H:i:s', $this->_startAt); 00059 } 00060 00066 public function getStopTime() 00067 { 00068 return date('dMY H:i:s', $this->_stopAt); 00069 } 00070 00076 public function getElapsedTime() 00077 { 00078 $totalSeconds = $this->_stopAt - $this->_startAt; 00079 $hours = floor($totalSeconds / 3600); 00080 $minutes = floor(($totalSeconds % 60) / 60); 00081 $seconds = ($totalSeconds % 3600); 00082 return str_pad($hours, 2, '0', STR_PAD_LEFT).':'.str_pad($minutes, 2, '0', STR_PAD_LEFT).':'.str_pad($seconds, 2, '0', STR_PAD_LEFT); 00083 } 00084 00088 private $_startAt; 00089 00093 private $_stopAt; 00094 } 00095 00096 ?>