Re: PHP 4.0 Bug #7115: Global is way slower then $GLOBALS

From: Date: Tue, 10 Oct 2000 09:57:18 +0000
Subject: Re: PHP 4.0 Bug #7115: Global is way slower then $GLOBALS
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-34561@lists.php.net to get a copy of this message
wico@cnh.nl writes: > From: wico@cnh.nl > Operating system: linux > PHP version: 4.0 Latest CVS (10/10/2000) > PHP Bug Type: Performance problem > Bug 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| +----------------------------------------------------------------+

« previous php.dev (#34561) next »