<?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>Red Stars &#187; Uncategorized</title>
	<atom:link href="http://blog.red-stars.net/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.red-stars.net</link>
	<description>Programming, food, and rambling</description>
	<lastBuildDate>Sat, 08 May 2010 16:19:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PHP Array Performance</title>
		<link>http://blog.red-stars.net/uncategorized/php-array-performance/</link>
		<comments>http://blog.red-stars.net/uncategorized/php-array-performance/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 13:42:02 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://blog.red-stars.net/?p=204</guid>
		<description><![CDATA[Index Checking The functional difference between array_key_exists($key, $array) and isset($array[$key]) is that isset returns false when the key exists but contains null. Functionality aside, there is a demonstrable performance difference. $dataSet = array(); $size = 0x1FFFF; $i = $size; while ($i--) $dataSet[$i] = $i+1; $start = microtime(true); $i = $size; while ($i--) array_key_exists($i, $dataSet); //isset($dataSet[$i]); [...]]]></description>
			<content:encoded><![CDATA[<span id="Index_Checking"><h3>Index Checking</h3></span>
<p>The functional difference between array_key_exists($key, $array) and isset($array[$key]) is that isset returns false when the key exists but contains null. Functionality aside, there is a demonstrable performance difference.</p>
<pre class="brush:php">$dataSet = array();
$size = 0x1FFFF;

$i = $size;
while ($i--)
	$dataSet[$i] = $i+1;

$start = microtime(true);

$i = $size;
while ($i--)
	array_key_exists($i, $dataSet); //isset($dataSet[$i]);

echo "Time: ". (microtime(true) - $start);</pre>
<p>Sure enough, after averaging a few benchmarks together the outcome was clear.</p>
<dl>
<dt>isset</dt>
<dd>0.0248870849609</dd>
<dt>array_key_exists</dt>
<dd>0.604112148285</dd>
</dl>
<p>When performance is important target isset() when applicable. It's even possible to use a fall through to increase performance, here's an example from my Options class: if (!isset($this->_options[$resolvedName]) &#038;& !array_key_exists($resolvedName, $this->_options))</p>
<span id="Append_Performance"><h3>Append Performance</h3></span>
<p>In the following test case there was no performance difference between usage of append or directly addressing an index.</p>
<pre class="brush:php">$dataSet = array();
$size = 0x1FFFF;
$i = $size;

$start = microtime(true);

while ($i--)
	$dataSet[] = $i+1; //$dataSet[$i] = $i+1;

echo "Time: ". (microtime(true) - $start);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.red-stars.net/uncategorized/php-array-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

