<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Perplexed Labs &#187; microtime</title>
	<atom:link href="http://blog.perplexedlabs.com/tag/microtime/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.perplexedlabs.com</link>
	<description>web development war stories from the frontlines to the backend</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:27:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>PHP Simple Profiling Class</title>
		<link>http://blog.perplexedlabs.com/2008/02/04/php-simple-profiling-class/</link>
		<comments>http://blog.perplexedlabs.com/2008/02/04/php-simple-profiling-class/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 18:47:58 +0000</pubDate>
		<dc:creator>Matt</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[execution time]]></category>
		<category><![CDATA[microtime]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://perplexedlabs.com/2008/02/04/php-simple-profiling-class/</guid>
		<description><![CDATA[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: &#60;?php $profiler = new cProfiler; $profiler-&#62;start(); // ... long block of code ... $et = $profiler-&#62;end(); echo 'longBlock et = '.$et.'&#60;br&#62;'; ?&#62; Class listing cProfiler.php: &#60;?php class cProfiler { [...]


Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2008/04/09/php-daisy-chain-class-method-calls/' rel='bookmark' title='Permanent Link: PHP Daisy Chain Class Method Calls'>PHP Daisy Chain Class Method Calls</a></li>
<li><a href='http://blog.perplexedlabs.com/2008/02/04/php-array-to-string/' rel='bookmark' title='Permanent Link: PHP Array to String'>PHP Array to String</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/04/22/php-named-parameters/' rel='bookmark' title='Permanent Link: PHP Named Parameters'>PHP Named Parameters</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Had to quickly get the execution time of certain segments of code so I whipped up this basic profiling class below.</p>
<p>Usage would go something like:</p>
<pre class="brush: php;">
&lt;?php
$profiler = new cProfiler;
$profiler-&gt;start();
// ... long block of code ...
$et = $profiler-&gt;end();
echo 'longBlock et = '.$et.'&lt;br&gt;';
?&gt;
</pre>
<p>Class listing cProfiler.php:</p>
<pre class="brush: php;">
&lt;?php

class cProfiler
{
	public $_i;

	public $stamps;
	public $ets;

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

	function __destruct() {}

	function _stamp() { return microtime(); }

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

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

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

		return $et;
	}
}

?&gt;
</pre>


<p>Related posts:<ol><li><a href='http://blog.perplexedlabs.com/2008/04/09/php-daisy-chain-class-method-calls/' rel='bookmark' title='Permanent Link: PHP Daisy Chain Class Method Calls'>PHP Daisy Chain Class Method Calls</a></li>
<li><a href='http://blog.perplexedlabs.com/2008/02/04/php-array-to-string/' rel='bookmark' title='Permanent Link: PHP Array to String'>PHP Array to String</a></li>
<li><a href='http://blog.perplexedlabs.com/2009/04/22/php-named-parameters/' rel='bookmark' title='Permanent Link: PHP Named Parameters'>PHP Named Parameters</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://blog.perplexedlabs.com/2008/02/04/php-simple-profiling-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
