Jak szybka jest tablica $GLOBALS w porównaniu np z np.
<?php function ta(){ } ?>
lub po prostu gdy zmieniam wartość elementu w tej tablicy to jak szybko to się dzieje w porównaniu z innymi sposobami przechowywania zmiennych.

<?php function ta(){ } ?>
<?php $x = $global_variable; // $GLOBALS[ 'global_variable' ] $global_variable = $x; ?>
<?php $GLOBALS['test'] = 'foo!!'; $test2 = 'foo!!'; function speedTest1($n) { for($i = 0; $i < $n; $i++){ } } function speedTest2($n) { for($i = 0; $i < $n; $i++){ } } function speedTest3($n) { for($i = 0; $i < $n; $i++){ } } function speedTest4($n) { for($i = 0; $i < $n; $i++){ } } speedTest1(100000); speedTest2(100000); speedTest3(100000); speedTest4(100000); ?>
<?php function get_time() { return ((float)$usec + (float)$sec); } $time_start = get_time(); //cały kod, którego czas wykonywania ma być zmierzony ?>
<pre><?php /* USAGE $timer = new Timer( 'timer_name' ); unset( $x ); */ class Timer { private $fStart_time; private $fStop_time; private $sTimer_name; public function __construct( $sTimer_name = '' ) { $this->sTimer_name = $sTimer_name; $this->fStart_time = $this->_microtime(); $this->fStop_time = 0; } public function getTime() { } private function _microtime() { } public function __destruct() { $this->fStop_time = $this->_microtime(); if ( $this->sTimer_name !== '' ) { } else { } return $this->fStop_time - $this->fStart_time; } } $global_variable = 6; $iterations = 2000000; $x1 = test_globals_speed_2( $iterations ); $x2 = test_globals_speed_1( $iterations ); function test_globals_speed_1( $iterations ) { $timer = new Timer( 'odwolanie do globalnych zmiennych za pomoca \"global $zmienna\"' ); $x = 0; for ( $i = 0; $i < $iterations; $i++ ) { $x = $global_variable; $global_variable = $x; } return $timer->getTime(); } function test_globals_speed_2( $iterations ) { $timer = new Timer( 'odwolanie do globalnych zmiennych za pomoca \"$GLOBALS[ 'zmienna' ]\"' ); $x = 0; for ( $i = 0; $i < $iterations; $i++ ) { $x = $GLOBALS[ 'global_variable' ]; $GLOBALS[ 'global_variable' ] = $x; } return $timer->getTime(); } ?></pre>