News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Ilia Alshanetsky's Blog:
Performance Analysis of isset() vs array_key_exists()
March 06, 2012 @ 08:44:31

Ilia Alshanetsky has posted about a performance difference he's found between using the isset and array_key_exists functions in PHP to see if a value exists.

At Confoo I had an interesting conversation with Guilherme Blanco regarding the fact that in Doctrine 2 they had a performance issue due to usage of array_key_exists() and how it was significantly slower than isset(). His anecdotal example was that doing isset() took 0.5 seconds, while array_key_exists() for the same operation took 5 seconds! That seemed wrong [...] so, I've decided to do a quick benchmark using a 5,000 element array.

His benchmarking code is included - it just loads up a simple data set from a file of "words" and measures the microtime between the isset and array_key_exists calls. His results do show that isset is the faster of the two (by 2.5x) but it's still a super small micro-optimization that won't gain you much in the end.

The bottom line is that if your application does not need to distinguish between an array key that does not exist and one whose value happens to be NULL you should use isset() because it happens to be a little faster.
0 comments voice your opinion now!
isset arraykeyexists benchmark large array code


blog comments powered by Disqus

Similar Posts

Rob Young's Blog: Chunking Large Queries with Iterators in PHP

Gareth Heyes' Blog: Non alphanumeric code in PHP

DevShed: Introducing the Memento Pattern

Reddit.com: Too many bugs and too much stress

PHPixie: Benchmarking Autoloading vs Combining classes into a single file


Community Events











Don't see your event here?
Let us know!


application facebook introduction install symfony2 hhvm composer language security example project hack framework database package unittest performance release podcast component

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework