I see a huge performance hit in the (command line) PHP script caused by simple assignment (runtime increases from 0.8 to 0.9 s to 29 times).
The script first extracts a lot of data from the MySQL database and creates objects of different user classes. After this selection (php now uses about 500 MB of RAM), I loop an array of approximately 3'500 Sample objects, each of which has an associative array (size about 100 records) as one of its properties. This array contains Value objects, which are small objects with two properties, and the keys are integers less than 6000. Here I came across a problem, see this code:
foreach ($samples as $id => $s) {
Please note that commented line. If I run the code as it appears here, this block runs from about 0.8 to 0.9 seconds . If I uncomment this single line, the block will run for almost 30 seconds . I found that if the array is not associative (it contains only serial keys from 0 to 100), the execution time increases only to 1.8 ~ 1.9 seconds.
It seems like this is due to the inconsistent array keys that I use, but again, why doesn't performance drop by calling isset($values[$match_id]) ? Is there a workaround for this or do I need to live with this?
Running PHP 5.3.0, Zend Engine v2.3.0, Mac OS X Server 10.6.2
command-line oop php
Pascal
source share