php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63736 array_key_exists extremely slow on referenced arrays
Submitted: 2012-12-10 13:39 UTC Modified: 2012-12-10 14:43 UTC
From: ymgve dot aa at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.4.9 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
48 - 22 = ?
Subscribe to this entry?

 
 [2012-12-10 13:39 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-10 14:43 UTC] johannes@php.net
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
 [2012-12-10 14:43 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 19:01:31 2024 UTC