From: [EMAIL PROTECTED] Operating system: i686-pc-linux-gnu PHP version: 4.0CVS-2001-11-26 PHP Bug Type: Performance problem Bug description: reference calls in some cases very slow
Hi, i have found a very critical behavior with references under php. The usage of references push in some cases the execution time extremly higher. I have written a small php script to explain the problem. The main problem is, the longer the string the higher the execution time, if you use a reference to the string. <?php // a function with using a reference to a parameter function with_reference (&$stream, $loopcounter){ for ($x=0;$x < $loopcounter; $x++){ $xyz=substr($stream,0,5); // i take only the first 5 characters } } // the same function, but without a reference function without_reference ($stream, $loopcounter){ for ($x=0;$x < $loopcounter; $x++){ $xyz=substr($stream,0,5); } } set_time_limit(60); $loopcount=100; // only 100 function calls! $streamsize=1048576; // 1MB, the longer the slower!!! Try 2MB. // First, made a big string for($x=0,$stream='';$x<$streamsize;$x++,$stream.='x'){} // Start function with a reference and measure start time $tmp = explode(' ', microtime()); $measure['Start Reference']=(double)$tmp[0] + (double)$tmp[1]; with_reference ($stream, $loopcount); // Start function without a reference $tmp = explode(' ', microtime()); $measure['Start Normal']=(double)$tmp[0] + (double)$tmp[1]; without_reference ($stream, $loopcount); // measure end time $tmp = explode(' ', microtime()); $measure['End']=(double)$tmp[0] + (double)$tmp[1]; // subtract times $with_ref_sec=$measure['Start Normal']-$measure['Start Reference']; $without_ref_sec=$measure['End']-$measure['Start Normal']; // output the times echo "<tt>"; echo "Loopcount: $loopcount<br>"; echo "String size: $streamsize<br>"; echo "Time for function request \"with_reference\" : "; echo $with_ref_sec; echo " secs<br>"; echo "Time for function request \"without_reference\": "; echo $without_ref_sec; echo " secs<hr>"; echo "execution time of without_reference is <b>".round($with_ref_sec/$without_ref_sec)."</b> times fast as with_reference!</tt>"; ?> -- Edit bug report at: http://bugs.php.net/?id=14237&edit=1 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]