News 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

ThinkPHP Blog: Handling large files with(out) PHP

Make Me Pulse Blog: Tips : RecursiveArrayIterator on mulitdimensional Array

WebDevLogs.com: Which way to get the PHP self script name is the fastest?

ImprovedSource.com: PHP v5.2 vs PHP v5.1

Lorna Mitchell: How NOT to Design Your API


Community Events





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


series laravel composer opinion community introduction symfony version tool library artisanfiles framework podcast language security release conference voicesoftheelephpant interview list

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