Bug #63736 [Opn->Nab]: array_key_exists extremely slow on referenced arrays
| From: | johannes@php.net | Date: | Mon, 10 Dec 2012 14:43:21 +0000 |
| Subject: | Bug #63736 [Opn->Nab]: array_key_exists extremely slow on referenced arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-175266@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63736&edit=1
ID: 63736
Updated by: johannes@php.net
Reported by: ymgve dot aa at gmail dot com
Summary: array_key_exists extremely slow on referenced arrays
-Status: Open
+Status: Not a bug
Type: Bug
Package: Performance problem
Operating System: Windows
PHP Version: 5.4.9
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
References disable copy-on-write.
http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html
has some details
Previous Comments:
------------------------------------------------------------------------
[2012-12-10 13:39:31] ymgve dot aa at gmail dot com
Description:
------------
When you use array_key_exists() on a referenced array, it performs extremely slow compared to
isset():
isset time 0.0053699016571045 size 0
isset time 0.0051219463348389 size 10
isset time 0.0032069683074951 size 100
isset time 0.0034000873565674 size 1000
isset time 0.0052909851074219 size 10000
array_key_exists time 0.0055620670318604 size 0
array_key_exists time 0.010941982269287 size 10
array_key_exists time 0.048230886459351 size 100
array_key_exists time 0.38906383514404 size 1000
array_key_exists time 5.6351599693298 size 10000
Due to the time increasing near linearly with the number of elements in the array, I assume the code
for some reason looks through the array key linearly instead of using a hash lookup.
Test script:
---------------
http://pastebin.com/PVrf96an
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63736&edit=1