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

Setfive.com: PHP: Some thoughts on using array_* with closures

Paul Jones: The Difference Between Factories, Registries, and Service Locators

CatsWhoCode.com: 10 code snippets to interact with Twitter

PHPMaster.com: PhalconPHP: Yet Another PHP Framework?

Felix Geisendorfer's Blog: Cake 1.2’s Set class eats nested arrays for breakfast!


Community Events





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


tips install series bugfix language laravel framework package interview library api release voicesoftheelephpant deployment opinion symfony community list podcast introduction

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