<?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>Atomized &#187; performance</title>
	<atom:link href="http://atomized.org/tag/performance/feed/" rel="self" type="application/rss+xml" />
	<link>http://atomized.org</link>
	<description>Fragmenting reality.</description>
	<lastBuildDate>Mon, 23 May 2011 23:46:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Really Damn Slow: A look at PHP objects</title>
		<link>http://atomized.org/2009/02/really-damn-slow-a-look-at-php-objects/</link>
		<comments>http://atomized.org/2009/02/really-damn-slow-a-look-at-php-objects/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 01:40:58 +0000</pubDate>
		<dc:creator>Ian</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://atomized.org/?p=516</guid>
		<description><![CDATA[A discussion came up at Digg today about the merits of arrays vs. stdClass instances. I’m generally in the stdClass camp, since I prefer the arrow syntax for accessing properties, and I was under the impression that there weren’t any other drawbacks. Boy, was I wrong. I benchmarked performance of arrays vs stdClass instances. I [...]]]></description>
			<content:encoded><![CDATA[<p>A discussion came up at <a href="http://digg.com">Digg</a> today about the merits of arrays vs. stdClass instances. I’m generally in the stdClass camp, since I prefer the arrow syntax for accessing properties, and I was under the impression that there weren’t any other drawbacks. Boy, was I wrong.</p>
<p>I benchmarked performance of arrays vs stdClass instances. I started with stdClass, and I knew it was going to be bad. The code was run like so:</p>
<pre>
$ time php blah.php
</pre>
<p>And the times were generated by running this three times and averaging the duration.</p>
<p>For arrays: .778 seconds</p>
<p>For objects: <b>6.516 seconds</b>.</p>
<p>Ouch! <i>Eight times</i> slower. Here’s the code:</p>
<pre language="php">
&lt;?php

for ($i = 0; $i &lt; 1000000; $i++) {
    $x = new stdClass;
    $x-&gt;a = 'a';
    $x-&gt;b = 'b';
}

?&gt;
</pre>
<pre language="php">
&lt;?php

for ($i = 0; $i &lt; 1000000; $i++) {
    $x = array();
    $x['a'] = 'a';
    $x['b'] = 'b';
}

?&gt;
</pre>
<p>The other thing is that there’s no object literal syntax in PHP like there is for arrays, so they can be less convenient. The array code is also slightly faster when using literal syntax: <code>$x = array('a' =&gt; 'a', 'b' =&gt; 'b')</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://atomized.org/2009/02/really-damn-slow-a-look-at-php-objects/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

