Had to quickly get the execution time of certain segments of code so I whipped up this basic profiling class below.

Usage would go something like:

<?php
$profiler = new cProfiler;
$profiler->start();
// ... long block of code ...
$et = $profiler->end();
echo 'longBlock et = '.$et.'<br>';
?>

Class listing cProfiler.php:

<?php

class cProfiler
{
	public $_i;

	public $stamps;
	public $ets;

	function __construct()
	{
		$this->_i = 0;
		$this->stamps = array();
		$this->ets = array();
	}

	function __destruct() {}

	function _stamp() { return microtime(); }

	function start() {
		$this->stamps[$this->_i] = $this->_stamp();
		$this->_i++;
	}

	function getET($id = '') { return $this->ets[$id]; }

	function end($id = '')
	{
		$timeend = $this->_stamp();
		$et = false;
		if($this->_i > 0) {
			$timestart = $this->stamps[$this->_i - 1];
			unset($this->stamps[$this->_i - 1]);
			$this->_i--;
			$et = number_format(((substr($timeend,0,9)) + (substr($timeend,-10)) - (substr($timestart,0,9)) - (substr($timestart,-10))),4);
			$this->ets[$id] = $et;
		}

		return $et;
	}
}

?>

Related posts:

  1. PHP Daisy Chain Class Method Calls
  2. PHP Array to String
  3. PHP Named Parameters
  4. PHP Parallel Web Scraper
  5. Tales of profiling when optimizing