<?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>Joseph Scott &#187; uphpu</title>
	<atom:link href="http://josephscott.org/archives/tag/uphpu/feed/" rel="self" type="application/rss+xml" />
	<link>http://josephscott.org</link>
	<description></description>
	<lastBuildDate>Mon, 06 Sep 2010 17:44:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://josephscott.org/?pushpress=hub'/>
		<item>
		<title>Slides: Anatomy of a PHP Request</title>
		<link>http://josephscott.org/archives/2010/04/slides-anatomy-of-a-php-request/</link>
		<comments>http://josephscott.org/archives/2010/04/slides-anatomy-of-a-php-request/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 15:15:58 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[slides]]></category>
		<category><![CDATA[uphpu]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=2197</guid>
		<description><![CDATA[Here are the slides from my presentation last week at UPHPU - Anatomy of a PHP Request View more presentations from josephscott. I added it to my slides page.]]></description>
			<content:encoded><![CDATA[<p>Here are the slides from my presentation last week at UPHPU -</p>
<div style="width:425px"><strong><a href="http://www.slideshare.net/josephscott/anatomy-of-a-php-request" title="Anatomy of a PHP Request">Anatomy of a PHP Request</a></strong>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/josephscott">josephscott</a>.</div>
</div>
<p>I added it to my <a href="http://josephscott.org/slides/">slides page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2010/04/slides-anatomy-of-a-php-request/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utah PHP Users Group Presentation: Anatomy of a PHP Request</title>
		<link>http://josephscott.org/archives/2010/04/utah-php-users-group-presentation-anatomy-of-a-php-request/</link>
		<comments>http://josephscott.org/archives/2010/04/utah-php-users-group-presentation-anatomy-of-a-php-request/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 15:28:45 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[uphpu]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=2169</guid>
		<description><![CDATA[I&#8217;ll be presenting at the next Utah PHP Users Group (UPHPU) meeting on Anatomy of a PHP Request: Ever wondered what really happens when your PHP script runs? I’ll cover the major milestones in the life and times of a &#8230; <a href="http://josephscott.org/archives/2010/04/utah-php-users-group-presentation-anatomy-of-a-php-request/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be presenting at the next <a href="http://uphpu.org/">Utah PHP Users Group (UPHPU)</a> meeting on <a href="http://uphpu.org/2010/04/08/uphpu-april-meeting-7pm-april-15-anatomy-of-a-php-request-joseph-scott-php-fundamentals-with-justin-carmony/#comments">Anatomy of a PHP Request</a>:</p>
<blockquote><p>
Ever wondered what really happens when your PHP script runs? I’ll cover the major milestones in the life and times of a PHP request (read, parse, compile, execute, output ) and where to look for road bumps along the way. There are lots of tools available to make your PHP purr like a kitten, so I’ll dive into op code caches (with APC), op code dumps (with VLD – Vulcan Logic Dumper), and profiling (with Xdebug and webgrind). It will be a great time digging a little deeper in to PHP!
</p></blockquote>
<p>The meeting is at:</p>
<p>April 15, 2010 @7pm</p>
<p>Bill Good Marketing<br />
12393 Gateway Park Place<br />
Suite 600<br />
Draper, UT 84020</p>
<p><a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=12393+Gateway+Park+Place+Suite+600+Draper,+UT+84020&amp;sll=40.525201,-111.901299&amp;sspn=0.00681,0.010772&amp;ie=UTF8&amp;hq=&amp;hnear=12393+Gateway+Park+Pl+%23600,+Draper,+Salt+Lake,+Utah+84020&amp;ll=40.525185,-111.902994&amp;spn=0.007307,0.010772&amp;t=k&amp;z=17&amp;iwloc=A">Google Map</a></p>
]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2010/04/utah-php-users-group-presentation-anatomy-of-a-php-request/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP Count Performance</title>
		<link>http://josephscott.org/archives/2010/01/php-count-performance/</link>
		<comments>http://josephscott.org/archives/2010/01/php-count-performance/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 16:41:57 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[count]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[uphpu]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=1674</guid>
		<description><![CDATA[There was a question on the Utah PHP user group email list recently that went something like this: is calling count() on an array once and storing the result in a variable better/faster than calling count() multiple times? I&#8217;d always &#8230; <a href="http://josephscott.org/archives/2010/01/php-count-performance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There was a question on the <a href="http://uphpu.org/">Utah PHP user group</a> email list recently that went something like this: is calling <a href="http://us.php.net/count/">count()</a> on an array once and storing the result in a variable better/faster than calling count() multiple times?</p>
<p>I&#8217;d always thought that if you were going to need the count of an array more than once then it was best to store the result in a variable.  This also felt intuitively correct, as count() was likely doing some amount of work to provide the requested data.  But I&#8217;d never really done any testing to confirm this was the case, so I figured this was a good time to determine if this long-held belief was correct.  The first step was to come up with some very basic test scripts.  Here&#8217;s the first one that calls count() multiple times (multi count):</p>
<pre class="brush: php;">
$data = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' );

if ( count( $data ) &gt; 1 ) { }

if ( count( $data ) &gt; 10 ) { }

if ( count( $data ) &gt; 20 ) { }

if ( count( $data ) &gt; 30 ) { }

if ( count( $data ) &gt; 40 ) { }

if ( count( $data ) &gt; 50 ) { }

if ( count( $data ) &gt; 100 ) { }
</pre>
<p>The second script (single count) calls count() once:</p>
<pre class="brush: php;">
$data = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' );

$num_data = count( $data );

if ( $num_data &gt; 1 ) { }

if ( $num_data &gt; 10 ) { }

if ( $num_data &gt; 20 ) { }

if ( $num_data &gt; 30 ) { }

if ( $num_data &gt; 40 ) { }

if ( $num_data &gt; 50 ) { }

if ( $num_data &gt; 100 ) { }
</pre>
<p>The idea was to make it simple and focus on count().  Next up was a few tests to see what PHP would do with these two chunks of code.</p>
<h5>VLD &#8211; PHP ops</h5>
<p><b>multi count:</b> 75 ops<br />
<b>single count:</b> 64 ops</p>
<p>To start with I used <a href="http://pecl.php.net/package/vld">vld</a> to see how many operations each one performed.  This confirms the idea that multi count requires more work for PHP, in this case 11 more ops for the simple test case.  It doesn&#8217;t provide specific weights to each op, but in general more ops means more work.</p>
<h5>Memory</h5>
<p><b>multi count:</b> 115,720 bytes<br />
<b>single count:</b> 115,704 bytes</p>
<p>On a whim I was curious if there was any memory usage difference.  I tested that with a call to <a href="http://us.php.net/memory_get_peak_usage">memory_get_peak_usage()</a> at the end of each script.  The specific number of bytes used isn&#8217;t important, just the difference.  The multi count script used an extra 16 bytes.  A very tiny difference to be sure, but a difference none the less.</p>
<h5>Execution Time (100,000 times)</h5>
<p><b>multi count:</b> 0.28717994689941 seconds<br />
<b>single count:</b> 0.10203385353088 seconds</p>
<p>For a final test I looped through the count/if section of the code 100,000 times to see if there was a difference in the execution time.  Looping 100,000 times was to make any difference a bit more obvious.  I limited it to the just the count/if section of the code because I didn&#8217;t want to include the time it took to initialize the array.  I ran this test over and over and the results were fairly consistent.</p>
<p>The single count approach was faster by 0.185 seconds.  This doesn&#8217;t sound like much, but the other way to look at this is that the multi count code was more than 2.5 times slower than the single count code.  That&#8217;s a pretty big ratio.</p>
<h5>Conclusion</h5>
<p>After running these tests it seems pretty clear that if you need to reference count() data more than once it&#8217;s better to store that value in a variable and reference that instead of calling count() multiple times.  The single count required few ops, less memory (by just a tiny amount), and executed faster.</p>
<p>Nice to see that my original thoughts on this are confirmed.</p>
]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2010/01/php-count-performance/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Presenting At Utah PHP Users (UPHPU) February Meeting</title>
		<link>http://josephscott.org/archives/2009/02/presenting-at-utah-php-users-uphpu-february-meeting/</link>
		<comments>http://josephscott.org/archives/2009/02/presenting-at-utah-php-users-uphpu-february-meeting/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 14:00:40 +0000</pubDate>
		<dc:creator>Joseph Scott</dc:creator>
				<category><![CDATA[Posts]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[uphpu]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://josephscott.org/?p=846</guid>
		<description><![CDATA[I&#8217;ll be presenting at the Utah PHP Users (UPHPU) meeting this Thursday. I&#8217;m going to cover the XML-RPC and AtomPub APIs in WordPress. UPHPU is a great group, it&#8217;s very casual and everyone seems to have a good time. We &#8230; <a href="http://josephscott.org/archives/2009/02/presenting-at-utah-php-users-uphpu-february-meeting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll be presenting at the <a href="http://uphpu.org/">Utah PHP Users (UPHPU)</a> meeting this Thursday.  I&#8217;m going to cover the XML-RPC and AtomPub APIs in WordPress.</p>
<p>UPHPU is a great group, it&#8217;s very casual and everyone seems to have a good time.  We usually got out to eat afterwards so come on down and make a night of it.</p>
]]></content:encoded>
			<wfw:commentRss>http://josephscott.org/archives/2009/02/presenting-at-utah-php-users-uphpu-february-meeting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
