php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38812 array_key_exists is ~200x slower than 5.1.x
Submitted: 2006-09-13 15:58 UTC Modified: 2006-09-20 00:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: chad at herballure dot com Assigned:
Status: Closed Package: Performance problem
PHP Version: 5CVS-2006-09-13 (snap) OS: Linux (SuSE 9.2)
Private report: No CVE-ID: None
 [2006-09-13 15:58 UTC] chad at herballure dot com
Description:
------------
array_key_exists takes about 16 times longer in PHP 5.2-200609131430 than it does in 5.1.[246].

Reproduce code:
---------------
http://www.sapphirepaw.org/ake_bug.txt
(depends on Benchmark_Iterate in PEAR)

Expected result:
----------------
The 5.1.x series produces numbers like:
ake_test:
Array
(
    [0] => 0.406023979187
    [1] => 0.285789966583
    [2] => 0.236785173416
    [3] => 0.22957110405
)


Actual result:
--------------
Yesterday's and todays 5.2 snapshots produce numbers like:
ake_test:
Array
(
    [0] => 4.45166897774
    [1] => 4.08239388466
    [2] => 4.0640411377
    [3] => 4.06054711342
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-13 17:01 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

The URL you provided doesn't work.
And please don't provide test cases that require PEAR.
Thank you.
 [2006-09-13 18:53 UTC] chad at herballure dot com
Your claim that the link "doesn't work" could not be verified. It displays the PHP script source code to reproduce the bug, as intended. We do not feel that running the benchmark and producing the output on our server is useful.

The code available at the link has been updated to no longer require PEAR. http://www.sapphirepaw.org/ake_bug.txt

New expected and actual results were generated using this code, revealing an actual difference between PHP versions of 204x.

Because isset() is a language feature, not a function call, an extra test was added to determine if function calls are what is expensive. The answer appears to be "no".

New expected result:
--------------------
ake_test:
Array
(
    [0] => 0.297938108444
    [1] => 0.211642026901
    [2] => 0.16384100914
    [3] => 0.153891801834
)
is1_test:
Array
(
    [0] => 0.193047046661
    [1] => 0.176480054855
    [2] => 0.168280124664
    [3] => 0.171167135239
)
is2_test:
Array
(
    [0] => 0.111315965652
    [1] => 0.112279176712
    [2] => 0.105856180191
    [3] => 0.109282016754
)

New actual result:
------------------
ake_test:
Array
(
    [0] => 36.2062079906
    [1] => 36.0692551136
    [2] => 36.0703611374
    [3] => 36.040956974
)
is1_test:
Array
(
    [0] => 0.17557311058
    [1] => 0.169100999832
    [2] => 0.169121026993
    [3] => 0.169019937515
)
is2_test:
Array
(
    [0] => 0.113948106766
    [1] => 0.108880996704
    [2] => 0.107892036438
    [3] => 0.110790014267
)
 [2006-09-14 00:25 UTC] judas dot iscariote at gmail dot com
==== PHP 5_2 debug mode ======
php array_key_exists.php
ake_test:
Array
(
    [0] => 222.61117291451
    [1] => 228.49721598625
    [2] => 235.83725214005
    [3] => 415.96051192284
)
is1_test:
Array
(
    [0] => 1.2712152004242
    [1] => 1.3619549274445
    [2] => 1.3896028995514
    [3] => 1.262256860733
)
is2_test:
Array
(
    [0] => 0.95932698249817
    [1] => 0.86532402038574
    [2] => 0.9735701084137
    [3] => 0.85658717155457
)
======== php 5.1.6 no debug ===========
cristian@hell:~/php-src> php5 array_key_exists.php
ake_test:
Array
(
    [0] => 0.23552083969116
    [1] => 0.22312307357788
    [2] => 0.22217798233032
    [3] => 0.22680497169495
)
is1_test:
Array
(
    [0] => 0.24776816368103
    [1] => 0.24320101737976
    [2] => 0.2431800365448
    [3] => 0.24098587036133
)
is2_test:
Array
(
    [0] => 0.15930700302124
    [1] => 0.16577696800232
    [2] => 0.15875005722046
    [3] => 0.15803599357605
)
 [2006-09-14 00:51 UTC] judas dot iscariote at gmail dot com
well, previuos test was not quite right 'cause I was testing a debug build against a non-debug build. this is the correct result

=== PHP 5_2 no debug, non zts==
== ** ./configure --disable-all **

./sapi/cli/php array_key_exists.php
ake_test:
Array
(
    [0] => 61.461007118225
    [1] => 58.933461904526
    [2] => 67.2141289711
    [3] => 60.613692998886
)
is1_test:
Array
(
    [0] => 0.17689299583435
    [1] => 0.16376399993896
    [2] => 0.22526001930237
    [3] => 0.16580605506897
)
is2_test:
Array
(
    [0] => 0.1137011051178
    [1] => 0.11136889457703
    [2] => 0.11219096183777
    [3] => 0.11238098144531
)

====== PHP 5_1 non debug, non zts ===
==== *** ./configure --disable-all ** ====


~/5.1/php-src> ./sapi/cli/php ~/php-src/array_key_exists.php
ake_test:
Array
(
    [0] => 0.13297486305237
    [1] => 0.12529993057251
    [2] => 0.12710905075073
    [3] => 0.12793111801147
)
is1_test:
Array
(
    [0] => 0.15972304344177
    [1] => 0.16012096405029
    [2] => 0.16134810447693
    [3] => 0.16280102729797
)
is2_test:
Array
(
    [0] => 0.10458111763
    [1] => 0.10124111175537
    [2] => 0.10496115684509
    [3] => 0.10187220573425
)
 [2006-09-14 08:20 UTC] tony2001@php.net
# telnet www.sapphirepaw.org 80
Trying 68.178.174.117...
telnet: connect to address 68.178.174.117: Connection refused

 [2006-09-14 08:33 UTC] judas dot iscariote at gmail dot com
here is the test case, in case you can't access it.
<?php

function ake_test($array, $wanted) { return (array_key_exists($wanted, $array)); }

function is1_helper($array, $wanted) { return (isset($array[$wanted])); }
function is1_test($array, $wanted) { return (is1_helper($array, $wanted)); } // make function call (as ake must)

function is2_test($array, $wanted) { return (isset($array[$wanted])); } // special lang feature, not a function...

$A = array();
for($i=1; $i < 2000; $i++) { $A["k{$i}y"] = "val_{$i}_ue"; } // build array to examine

$tests = array('ake', 'is1', 'is2');
foreach($tests as $test) {
	$func = $test . '_test';
	$r = array(); // benchmark results
	echo("$func:\n");
	for($outer = 0; $outer < 4; ++$outer) {
		$starttime = microtime(true);
		for($inner = 0; $inner < 100000; ++$inner) { $func($A, 'k1388y'); }
		array_push($r, microtime(true) - $starttime); // record elapsed realtime
	}
	print_r($r);
}

?>
 [2006-09-14 15:23 UTC] chad at herballure dot com
Tony, that seems to be your problem. The Web server and firewall have certainly been running and unmodified since this bug report was opened, and the rest of the world seems to have no trouble getting there.
 [2006-09-20 00:29 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC