<?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>Professional PHP &#187; benchmarks</title>
	<atom:link href="http://www.procata.com/blog/archives/tag/benchmarks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.procata.com/blog</link>
	<description>PHP Programming, Web Development, PHP Advocacy and PHP Best Practices.</description>
	<lastBuildDate>Fri, 10 Dec 2010 17:23:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Benchmarking PHP&#8217;s Magic Methods</title>
		<link>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/</link>
		<comments>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/#comments</comments>
		<pubDate>Mon, 05 Nov 2007 00:01:02 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Software Design]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[performance-optimization]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/</guid>
		<description><![CDATA[Larry Garfield has an interesting set of benchmarks covering many of PHP&#8217;s magic methods.  His results correspond pretty well to my own benchmarks in the area.  The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them.  Its hard to [...]]]></description>
			<content:encoded><![CDATA[<p>Larry Garfield has an interesting <a href="http://www.garfieldtech.com/blog/magic-benchmarks">set of benchmarks</a> covering many of PHP&#8217;s <a href="http://php.net/oop5.magic">magic methods</a>.  His results correspond pretty well to my own benchmarks in the area.  The thing to take away is that its not necessarily the overhead of the magic methods, but rather what you do inside them.  Its hard to do anything useful inside a magic method, such as __get or __call that isn&#8217;t <b>10 to 20 times slower</b> than the &#8220;non-magic&#8221; solution.</p>
<p>There are probably more than a few naive programmers who would read results like this and start to avoid these constructs in their own code for performance reasons.  These are the same kinds of people obsessing over a few single or double quotes, who eschew &#8220;slow&#8221; objects in favor of switch statements that are many times slower than the polymorphic method calls they are trying to avoid.</p>
<p>But, that&#8217;s not the end of the story.  Larry ran his benchmarks using 2,000,000 iterations.  The <b>N</b> really matters here.  Sure, iterators are slower than arrays, but you aren&#8217;t going to be iterating over two million things.  I tend to fetch my database records in lots of 25 or 50.  You aren&#8217;t going to be making two million invocations of __call.  But how many will you make?  Under what value of N does the performance of these techniques cease to matter?  Is it ten, one hundred, one thousand, or ten thousand?  You may be surprised at how few calls your program actually does and how little impact it has on performance.</p>
<p>As <a href="http://netevil.org/">Wez</a> and <a href="http://www.travisswicegood.com/">Travis</a> point out in their comments, profiling is the way to find out the potential impact and to discover your true N.</p>
<p>Paul M. Jones has a <a href="http://paul-m-jones.com/blog/?p=182">good example</a> of what I&#8217;m talking about.  There, call_user_func_array appears to be a bottleneck, but it turns out that its the function being called, htmlspecialchars, not the calling process that consumes the balance of the time.  In that case, the function was &#8220;only&#8221; called 300 times.  I find that order of magnitude to be fairly typical.  Something to be aware of, perhaps, but not something to obsess over.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2007/11/04/benchmarking-phps-magic-methods/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>A Glimpse into the Future: PHP 6</title>
		<link>http://www.procata.com/blog/archives/2005/11/22/a-glimpse-into-the-future-php-6/</link>
		<comments>http://www.procata.com/blog/archives/2005/11/22/a-glimpse-into-the-future-php-6/#comments</comments>
		<pubDate>Tue, 22 Nov 2005 20:40:09 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[performance-optimization]]></category>
		<category><![CDATA[php-5]]></category>
		<category><![CDATA[php-6]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/?p=158</guid>
		<description><![CDATA[Derick Rethans has posted the notes from the recent PHP 6 meeting in Paris.  All I can say is wow!  PHP has a bright future.  Good job guys.
I&#8217;ve also been impressed with the new upgrade notes for 5.1.  Good job there, too.
I&#8217;ve read over the whole thing and I like what [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.derickrethans.nl/">Derick Rethans</a> has posted the <a href="http://www.php.net/~derick/meeting-notes.html">notes from the recent PHP 6 meeting</a> in Paris.  All I can say is wow!  PHP has a bright future.  Good job guys.</p>
<p>I&#8217;ve also been impressed with the new upgrade notes for 5.1.  Good job there, too.</p>
<p>I&#8217;ve read over the whole thing and I like what I see.  One thing did jump out at me.</p>
<blockquote><p>
We also discussed whether we should even allow Unicode mode to be turned off as current micro benchmarks show that the Unicode implementations of some of the string functions are up to 300% slower, and whole applications up to 25% slower. Disallowing Unicode mode to be turned off is expected to slow down the adoption of PHP 6 too as many ISPs would be reluctant to install a version that immediately slows down the applications of their users.
</p></blockquote>
<p>I am definitely not familiar with all the issues involved, but wouldn&#8217;t this make it hard to write general purpose PHP applications?  Programs would have to check whether unicode was on or off?  Wouldn&#8217;t that checking be slow and complicated, too?</p>
<p>I think its great to discuss ways to improve adoption of PHP 6 so far ahead.  It looks like APC will be included.  I think thats great news on the adoption front.</p>
<p>I wonder, though, if anyone has gone and asked hosting companies what features they might like to see in PHP 6?  I also wonder if it would be helpful to have two upgrade guides: one for programmers and one for hosts.  Perhaps even a separate Hosting PHP Applications section as part of the PHP manual.  (With things like &#8220;How do I find out which PHP script sent out this spam?&#8221;) </p>
<p>PHP hosting concerns are not always the same as PHP programmer concerns.  Hosts are important to the adoption of PHP and throwing them some love can only be a good thing for the platform as a whole.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2005/11/22/a-glimpse-into-the-future-php-6/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Microbenchmarks of single and double qouting.</title>
		<link>http://www.procata.com/blog/archives/2005/03/08/microbenchmarks-of-single-and-double-qouting/</link>
		<comments>http://www.procata.com/blog/archives/2005/03/08/microbenchmarks-of-single-and-double-qouting/#comments</comments>
		<pubDate>Tue, 08 Mar 2005 23:20:48 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[performance-optimization]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2005/03/08/microbenchmarks-of-single-and-double-qouting/</guid>
		<description><![CDATA[I wrote earlier about flawed microbenchmarks.  Today on sitepoint, there was a post on the performance of single versus double quotes in PHP based on a microbenchmark:

The reasoning behind this speedup is that when the PHP compiler encounters a string constant beginning with a double quote, the string itself must be parsed and special [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote earlier about <a href="http://www.procata.com/blog/archives/2005/02/24/flawed-microbenchmarks/">flawed microbenchmarks</a>.  Today on <a href="http://www.sitepoint.com/blog-view.php?blogid=9">sitepoint</a>, there was a post on the performance of single versus double quotes in PHP based on a microbenchmark:</p>
<blockquote><p>
The reasoning behind this speedup is that when the PHP compiler encounters a string constant beginning with a double quote, the string itself must be parsed and special characters (such as $, \ and {) have special meanings. By contrast, if a string constant begins with a single quote, only the backslash has a special meaning, and therefore PHP doesn&#8217;t have to worry about replacing variables and expressions embedded in the string.
</p></blockquote>
<p>This line of thought is flawed for two reasons.  </p>
<p>First, PHP uses <a href="http://www.gnu.org/software/flex/">flex</a> to tokenize the php source code.  Flex is a table driven lexer.  It doesn&#8217;t necessarily follow that having more characters with special meaning makes flex slower if you don&#8217;t actually use those characters.</p>
<p>Second, the <a href="http://insighttoinjury.com/archives/2005/02/27/php-speed-differences/">original benchmark</a> doesn&#8217;t actually measure parsing time.  Like all microtime() based benchmarks, the first access of microtime() doesn&#8217;t happen until the php file is completely parsed and converted into opcodes.  Additionally, it executed each literal inside a 10,000 iteration loop.  Thats 1 time to parse it and 10,000 times to execute it.</p>
<p>I put together a different benchmark that does measure parsing time.  It consists of two files<br />
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'very long string'</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre><br />
and<br />
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;very long string&quot;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre></p>
<p>The very long string I used was the text of the US constitution: 27,787 bytes.  I measured using ab, which includes parsing time.  My results:</p>
<p>single quotes: 27.59 ms<br />
double quotes:  27.74 ms</p>
<p>Hardly earth-shattering. Single quotes was consistently faster, but by the same minor margin.  This is with a 27k literal string. My guess is that you will never have enough literals in a typical PHP program for any parsing performance differential to matter.</p>
<p>Is there an execution differential?  Do both of these constructs generate the same opcodes?  I tried to check it out using <a href="http://www.derickrethans.nl/vld.php">Vld</a> or <a href="http://us4.php.net/ref.parsekit">parsekit</a> but I can&#8217;t get either of these to work in my development environment (OS X).  Perhaps someone will reply in a comment with the opcodes for the previous two programs and settle the question.</p>
<p>There doesn&#8217;t seem to be much if any difference between single and double quotes for an identical string.  A more interesting question would be what happens when the strings aren&#8217;t identical.  Consider the following three examples:<br />
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">&quot;Answer: $answer!&quot;</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre><br />
versus<br />
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'Answer: '</span>, <span style="color: #0000ff;">$answer</span>, <span style="color: #ff0000;">'!'</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre><br />
or<br />
<pre class="php">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">'Answer: '</span> . <span style="color: #0000ff;">$answer</span> . <span style="color: #ff0000;">'!'</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;</pre><br />
or<br />
<pre class="php">&nbsp;
Answer: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$answer</span>; <span style="color: #000000; font-weight: bold;">?&gt;</span>!
&nbsp;</pre><br />
Which one do you think is faster?  </p>
<p>My gut feeling is that concatenation is slower because of the ability of the output buffer to allocate memory in big chunks rather than little chunks.  Other than that, I honestly don&#8217;t think it makes a difference, but I would love to compare the opcodes for each of these examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2005/03/08/microbenchmarks-of-single-and-double-qouting/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Flawed Microbenchmarks</title>
		<link>http://www.procata.com/blog/archives/2005/02/24/flawed-microbenchmarks/</link>
		<comments>http://www.procata.com/blog/archives/2005/02/24/flawed-microbenchmarks/#comments</comments>
		<pubDate>Thu, 24 Feb 2005 20:58:54 +0000</pubDate>
		<dc:creator>Jeff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[benchmarks]]></category>

		<guid isPermaLink="false">http://www.procata.com/blog/archives/2005/02/24/microbenchmark-flaws/</guid>
		<description><![CDATA[Anatomy of a flawed microbenchmark highlights some of the problems involved in creating microbenchmarks (Java oriented).

The scary thing about microbenchmarks is that they always produce a number, even if that number is meaningless. They measure something, we&#8217;re just not sure what. Very often, they only measure the performance of the specific microbenchmark, and nothing more. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www-128.ibm.com/developerworks/java/library/j-jtp02225.html?ca=drs-j0805">Anatomy of a flawed microbenchmark</a> highlights some of the problems involved in creating microbenchmarks (Java oriented).</p>
<blockquote><p>
The scary thing about microbenchmarks is that they always produce a number, even if that number is meaningless. They measure something, we&#8217;re just not sure what. Very often, they only measure the performance of the specific microbenchmark, and nothing more. But it is very easy to convince yourself that your benchmark measures the performance of a specific construct, and erroneously conclude something about the performance of that construct.</p>
<p>Even when you write an excellent benchmark, your results may be only valid on the system you ran it on. If you run your tests on a single-processor laptop system with a small amount of memory, you may not be able to conclude anything about the performance on a server system.
</p></blockquote>
<p>This is why I prefer to benchmark with ab rather than microtime().</p>
]]></content:encoded>
			<wfw:commentRss>http://www.procata.com/blog/archives/2005/02/24/flawed-microbenchmarks/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

