<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Kommentare zu: PHP: Benchmark isset() or array_key_exists() ?</title>
	<atom:link href="http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/feed" rel="self" type="application/rss+xml" />
	<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html</link>
	<description>Ich bin nicht verrückt, nur technisch begabt ...</description>
	<lastBuildDate>Fri, 26 Sep 2014 12:04:55 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Von: DaHaiz</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1699</link>
		<dc:creator>DaHaiz</dc:creator>
		<pubDate>Mon, 28 Jul 2014 14:12:44 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1699</guid>
		<description>Little comment:
On your point that array_key_exists has to search the whole array (and Steffen Haugk) and isset do not:
Arrays (the keys) are organized as HashTables internally. HashTables have access time O(1), not O(n) (read &quot;look on every key if it fits&quot;) like you said. HashTables &quot;know&quot; where the key would be if it exists and therefore do not have to search the whole array. Conclusion: This won&#039;t be the cause for the performance difference between isset and array_key_exists.</description>
		<content:encoded><![CDATA[<p>Little comment:<br />
On your point that array_key_exists has to search the whole array (and Steffen Haugk) and isset do not:<br />
Arrays (the keys) are organized as HashTables internally. HashTables have access time O(1), not O(n) (read "look on every key if it fits") like you said. HashTables "know" where the key would be if it exists and therefore do not have to search the whole array. Conclusion: This won't be the cause for the performance difference between isset and array_key_exists.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: scragar</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1641</link>
		<dc:creator>scragar</dc:creator>
		<pubDate>Fri, 11 Apr 2014 13:32:06 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1641</guid>
		<description>Just in case you&#039;re curious the actual reason why array_key_exists is because it&#039;s a function call, while isset is a language construct.

isset being a language construct means it can bypass a lot of really slow internal function wrapping. The internal function wrapping is not exactly slow, but it&#039;s a constant time added to any function call.

cast is by far the slowest because of your implimentation, every time you write @something PHP creates a note of the current stack location, takes a copy of it&#039;s error handling settings, turns error handling off, evaluates the code, checking with every expression if it&#039;s reached the point it recorded earlier, then once it returns back to the point it needs to be at it then turns error handling back on. Without the @ symbol it&#039;ll run at less than half that time, and with error handling turned off explicitly before the loop you&#039;re looking at it being almost as fast as array_key_exists, which can be made to actually be almost as fast as isset by replacing the cast with a double negation.

$devnull = !!$array[$i++];</description>
		<content:encoded><![CDATA[<p>Just in case you're curious the actual reason why array_key_exists is because it's a function call, while isset is a language construct.</p>
<p>isset being a language construct means it can bypass a lot of really slow internal function wrapping. The internal function wrapping is not exactly slow, but it's a constant time added to any function call.</p>
<p>cast is by far the slowest because of your implimentation, every time you write @something PHP creates a note of the current stack location, takes a copy of it's error handling settings, turns error handling off, evaluates the code, checking with every expression if it's reached the point it recorded earlier, then once it returns back to the point it needs to be at it then turns error handling back on. Without the @ symbol it'll run at less than half that time, and with error handling turned off explicitly before the loop you're looking at it being almost as fast as array_key_exists, which can be made to actually be almost as fast as isset by replacing the cast with a double negation.</p>
<p>$devnull = !!$array[$i++];</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Sebastian Bernt</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1548</link>
		<dc:creator>Sebastian Bernt</dc:creator>
		<pubDate>Tue, 26 Feb 2013 08:32:25 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1548</guid>
		<description>Regarding your wondering why casting is so slow:

Casting is slow in nearly all programming languages, as this is a reflection. Depending on the language it is a class or object reflection. In most languages it is an object reflection as you reflect over the object to cast it.

You should avoid any kind of reflection when it comes to performance optimization. Typical (PHP) reflections: call_user_func, instanceof, new $classname, casting</description>
		<content:encoded><![CDATA[<p>Regarding your wondering why casting is so slow:</p>
<p>Casting is slow in nearly all programming languages, as this is a reflection. Depending on the language it is a class or object reflection. In most languages it is an object reflection as you reflect over the object to cast it.</p>
<p>You should avoid any kind of reflection when it comes to performance optimization. Typical (PHP) reflections: call_user_func, instanceof, new $classname, casting</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Steffen Haugk</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1510</link>
		<dc:creator>Steffen Haugk</dc:creator>
		<pubDate>Tue, 26 Jun 2012 10:05:55 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1510</guid>
		<description>Not sure you have explained very well why isset() is faster. You say isset() only needs to access it whilst array_key_exists() needs to search the entire array. How does isset() access without searching the entire array? Why doesn&#039;t array_key_exists() simply access?

The benchmark times are skewed by including the time it takes to run a for loop. If you take that out you will find that isset() is much faster, not only 60%.</description>
		<content:encoded><![CDATA[<p>Not sure you have explained very well why isset() is faster. You say isset() only needs to access it whilst array_key_exists() needs to search the entire array. How does isset() access without searching the entire array? Why doesn't array_key_exists() simply access?</p>
<p>The benchmark times are skewed by including the time it takes to run a for loop. If you take that out you will find that isset() is much faster, not only 60%.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: PHP array_key_exists vs. isset()</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1490</link>
		<dc:creator>PHP array_key_exists vs. isset()</dc:creator>
		<pubDate>Fri, 20 Apr 2012 23:14:28 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1490</guid>
		<description>[...] If you said &#8220;isset&#8221;, you&#8217;d be right! It is approximately 60% faster, as others have noted. [...]</description>
		<content:encoded><![CDATA[<p>[...] If you said &#8220;isset&#8221;, you&#8217;d be right! It is approximately 60% faster, as others have noted. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: VVVVV</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1480</link>
		<dc:creator>VVVVV</dc:creator>
		<pubDate>Fri, 17 Feb 2012 10:32:36 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1480</guid>
		<description>In fact, &#039;isset()&#039; is not a function. It&#039;s parsed by Zend parser and executed internally. It doesn&#039;t need to convert to lower case or scan function table. But, &#039;array_key_exists&#039; does.</description>
		<content:encoded><![CDATA[<p>In fact, 'isset()' is not a function. It's parsed by Zend parser and executed internally. It doesn't need to convert to lower case or scan function table. But, 'array_key_exists' does.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Nik Tang</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1398</link>
		<dc:creator>Nik Tang</dc:creator>
		<pubDate>Mon, 04 Jul 2011 07:32:51 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1398</guid>
		<description>I have proposed a method by combining the isset() and array_key_exists() so that its performance is very close to isset() while providing the same result as array_key_exists() does.

If you&#039;re interested, just check it out here: http://www.zomeoff.com/php-fast-way-to-determine-a-keyelements-existance-in-an-array/</description>
		<content:encoded><![CDATA[<p>I have proposed a method by combining the isset() and array_key_exists() so that its performance is very close to isset() while providing the same result as array_key_exists() does.</p>
<p>If you're interested, just check it out here: <a href="http://www.zomeoff.com/php-fast-way-to-determine-a-keyelements-existance-in-an-array/" rel="nofollow">http://www.zomeoff.com/php-fast-way-to-determine-a-keyelements-existance-in-an-array/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: MFix</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-1115</link>
		<dc:creator>MFix</dc:creator>
		<pubDate>Mon, 25 Apr 2011 19:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-1115</guid>
		<description>You have written: &quot;But i still do not really know why the cast is so slow&quot;.
The answer is pretty simple - not the cast is slow, but error reporting switch is.

Using @ works like:
$tmp = error_reporting();
error_reporting(0);
// do cast
error_reporting($tmp);</description>
		<content:encoded><![CDATA[<p>You have written: "But i still do not really know why the cast is so slow".<br />
The answer is pretty simple - not the cast is slow, but error reporting switch is.</p>
<p>Using @ works like:<br />
$tmp = error_reporting();<br />
error_reporting(0);<br />
// do cast<br />
error_reporting($tmp);</p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: nerkn</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-698</link>
		<dc:creator>nerkn</dc:creator>
		<pubDate>Wed, 04 Aug 2010 07:06:25 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-698</guid>
		<description>I use to check if the value is usable. Null I know from the mysql definition reads “a missing unknown value”. 

If I&#039;m concerning the existance of a value I could surely use isset. If I use keys like an array, the importance is the being there, use array_key_exists is the function.

thanks for benchmarks, I thouht there is huge difference than your results, since one is function, doing many things, and other one is lang construct.


http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html</description>
		<content:encoded><![CDATA[<p>I use to check if the value is usable. Null I know from the mysql definition reads “a missing unknown value”. </p>
<p>If I'm concerning the existance of a value I could surely use isset. If I use keys like an array, the importance is the being there, use array_key_exists is the function.</p>
<p>thanks for benchmarks, I thouht there is huge difference than your results, since one is function, doing many things, and other one is lang construct.</p>
<p><a href="http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html" rel="nofollow">http://dev.mysql.com/doc/refman/5.0/en/working-with-null.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Von: Julius</title>
		<link>http://juliusbeckmann.de/blog/php-benchmark-isset-or-array_key_exists.html/comment-page-1#comment-432</link>
		<dc:creator>Julius</dc:creator>
		<pubDate>Wed, 19 Aug 2009 20:34:30 +0000</pubDate>
		<guid isPermaLink="false">http://juliusbeckmann.de/blog/?p=400#comment-432</guid>
		<description>Thats correct Caio.
It also explains why array_key_exists is slower than isset.
But i cant fairly remember a scenairo where i would have needed exactly that behaviour only array_key_exists() has.

I checked documentation, it is mentioned there http://php.net/array_key_exists need to look closer next time :D</description>
		<content:encoded><![CDATA[<p>Thats correct Caio.<br />
It also explains why array_key_exists is slower than isset.<br />
But i cant fairly remember a scenairo where i would have needed exactly that behaviour only array_key_exists() has.</p>
<p>I checked documentation, it is mentioned there <a href="http://php.net/array_key_exists" rel="nofollow">http://php.net/array_key_exists</a> need to look closer next time :D</p>
]]></content:encoded>
	</item>
</channel>
</rss>
