|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-12-18 22:55 UTC] lindsay at notion dot co
[2014-12-18 23:12 UTC] nikic@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: nikic
[2014-12-18 23:12 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 07:00:02 2025 UTC |
Description: ------------ Within a function, if an array is passed in by reference, operations on the array get slow within the function as the array grows. In this example, is_array() gets much slower. Here is output from the example script with and with out the array variable being passed as reference. walk_array 10000 0.039294004440308 20000 0.031054973602295 30000 0.026264190673828 40000 0.025592803955078 50000 0.026119947433472 60000 0.025648832321167 70000 0.026489973068237 80000 0.023653984069824 90000 0.028777122497559 walk_array_by_reference 10000 1.7504909038544 20000 6.3624141216278 30000 14.600469827652 40000 28.24251294136 50000 37.910901069641 60000 46.824372053146 70000 60.680932044983 80000 71.826647043228 90000 78.522189855576 Tested against 'PHP 5.5.14-2+deb.sury.org~precise+1 (cli)' and 'PHP 5.6.2 (cli)' Test script: --------------- <?php define('LOOP_COUNT', 100000); define('LOOP_PRINT', 10000); $array = []; walk_array($array); walk_array_by_reference($array); function walk_array($array) { echo 'walk_array' . PHP_EOL; $timer = microtime(true); for ($i = 1; $i < LOOP_COUNT; $i++) { if ($i % LOOP_PRINT == 0) { echo $i . ' ' . (microtime(true) - $timer) . PHP_EOL; $timer = microtime(true); } $array[$i] = 1; if (is_array($array)) {} } } function walk_array_by_reference(&$array) { echo 'walk_array_by_reference' . PHP_EOL; $timer = microtime(true); for ($i = 1; $i < LOOP_COUNT; $i++) { if ($i % LOOP_PRINT == 0) { echo $i . ' ' . (microtime(true) - $timer) . PHP_EOL; $timer = microtime(true); } $array[$i] = 1; if (is_array($array)) {} } }