Re: PHP 4.0 Bug #7115: Global is way slower then $GLOBALS
| From: | Wico de Leeuw | Date: | Tue, 10 Oct 2000 10:16:00 +0000 |
| Subject: | Re: PHP 4.0 Bug #7115: Global is way slower then $GLOBALS | ||
| References: | 1 2 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-34563@lists.php.net to get a copy of this message | ||
At 02:57 10-10-00 -0700, Lars Torben Wilson wrote:
wico@cnh.nl writes:Hmm, The file is an normal ascii file with no weird chars or whatever (It's kinda an export looks like csv-file) What could be wrong? Greetz, WicoFrom: wico@cnh.nlOperating system: linuxPHP version: 4.0 Latest CVS (10/10/2000) PHP Bug Type: Performance problemBug description: Global is way slower then $GLOBALS hiya $ADLIB_DATA is a ARRAY of a file of 8 meg count($ADLIB_DATA) = 369459 ofcourse this all is in a function (file_init and getting the data is outside the function) for ($x = 0; $x < 33; $x++) { $data .= $GLOBALS[ADLIB_DATA][$x]; } echo time() - $test . " seconden<BR>\n\n"; this takes 1 sec GLOBAL $ADLIB_DATA; for ($x = 0; $x < 33; $x++) { $data .= ADLIB_DATA[$x]; } echo time() - $test . " seconden<BR>\n\n"; this takes 20 sec!!! Something weird? Greetz, Wico I'm starting to wonder whether either the file load time or some other factor is at play here--even though you did say otherwise. :) I just tried this, using the following code:
$file = file('/home/torben/INBOX'); function using_global() {global $file; $data = ''; for ($x = 0; $x < 3300; $x++) { $data .= $file[$x]; }} function using_globals() {$data = ''; for ($x = 0; $x < 3300; $x++) { $data .= $GLOBALS['file'][$x]; }} ...and running each function 100 times. Each typically takes 6.5-7 seconds to run 100 times, with never more than half a second between them (with the first function usually being the faster one). -- +----------------------------------------------------------------+|Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi|+----------------------------------------------------------------+