Location: PHPKode > scripts > Speed Diagnostic > speed-diagnostic/speedDiagnostic.class.php
<?php
	/**
	 * @version 	$Id :speedDiagnostic.class.php
	 * @author 		Sanjeev Kumar<hide@address.com>
	 * @copyright   
	 * 
	 * This class give us way to find out speed or execution time of a script or function
	 * 
	 * 
	 */
	
	
	/**
	 * global variable for start and end time
	 * @var $startTime array
	 * @var $endTime array
	 */
	
	$startTime = array();
	$endTime = array();
	
	/**
	 *  bug mode = 1  ,On debug mode
	 *  bug mode = 0  ,Off debug mode 
	 */
	
	$bugMode = 1 ;
	
	class speedDiagnostic
	{
		
		/**
		 * start time
		 * @access private
		 */
		private $m_iStartTime;
		
		/**
		 * End time
		 * @access private
		 */
		
		private $m_iEndTime;
		
		/**
		 * class construction
		 *
		 */
		public function __construct(){
			
		}
		
		/**
		 * push start time 
		 * @param string $functionName
		 */
		
		public function start($functionName)
		{    
			global $startTime;
			
			global $bugMode;
			if($bugMode == '1'){
			$this->m_iStartTime = microtime(true);
			array_push($startTime,$functionName,$this->m_iStartTime);
			}
			
		}
		
		/**
		 * push end time
		 *
		 * @param string $functionName
		 */
		public function stop($functionName)
		{
			global $endTime ;
			global $bugMode;
			if($bugMode == '1'){
			$this->m_iEndTime = microtime(true);
			array_push($endTime,$functionName,$this->m_iEndTime);
			}
		}
		
        /**
         * display table formate of execution time
         *
         * @return string
         */
	   
	   public function display(){
	   	
	   	global $startTime;
	   	global $endTime ;
	   	
	   	global $bugMode;
			if($bugMode == '1'){
	   	
			foreach ($startTime as $key => $val){
			if($key%2){
			
			$endTime1[] = $endTime[$key];
			$startTime1[] = $val;
			}else {
			
			$functionname[] = $val;
			}
	   	
	   }
	   
	   
	   $str = '
<table border="0" cellpadding="2" cellspacing="2" width="100%">
 <tr>
 <th align="left">Function Name</th>
 
 
 <th align="left">Total Time sec.</th>

 </tr>';
	   
	 for($i=0; $i < count($startTime1);$i++){
	 	
	 	$str .= '<tr>';
	 	$str .= '<td>'.$functionname[$i].'</td>';
	 	/*
	 	$str .= '<td>'.$startTime1[$i].'</td>';
	 	$str .= '<td>'.$endTime1[$i].'</td>';
	 	*/
	 	$str .= '<td>'.round($endTime1[$i] - $startTime1[$i],6).'</td>';
	 	
	 	
	 	$str .= '</tr>';
	 	
	 	
	 }

	 $str .= '</table>';
	 
	 unset($startTime);
	 unset($endTime);
	 return $str;
	   
	}
	   
	   
	   }
	
	
	}
	
?>
Return current item: Speed Diagnostic