[TYPO3-core] RFC: #847: error in tslib_fe->getFromCache()

Dmitry Dulepov [typo3] dmitry at typo3.org
Sat Jul 26 16:24:27 CEST 2008


Hi!

Steffen Kamper wrote:
> ok, here are your numbers:
> 
> $s = microtime(1);
> for ($i = 0; $i < 100000; $i++) { if($GLOBALS['not_existing']) {$k++;} }
> $e = microtime(1);
> echo 'Time needed without isset: ' . ($e-$s) . "\n";
> 
> $s = microtime(1);
> for ($i = 0; $i < 100000; $i++) { if(isset($GLOBALS['not_existing'])) 
> {$k++;} }
> $e = microtime(1);
> echo 'Time needed with isset: ' . ($e-$s) . "\n";
> 
> Output:
> Time needed without isset: 1.60987997055
> Time needed with isset: 0.0281138420105
> 
> You see that performance increased with factor 80
> 
> impressed?

Not at all. You did not reproduce the case we are talking about but made a test over $GLOBALS. This is not correct testing. My example:

======================
<?php                                                                                                                                                 
                                                                                                                                                      
$t = new stdClass();                                                                                                                                  
$t->config['config'] = array();                                                                                                                       
                                                                                                                                                      
$k = 0;                                                                                                                                               
$t1 = microtime(true);                                                                                                                                
for ($i = 0; $i < 100000; $i++) {                                                                                                                     
    if ($t->config['config']['debug']) {                                                                                                              
        $k = $t->config['config']['debug'] + 1;                                                                                                       
    }                                                                                                                                                 
}                                                                                                                                                     
$t2 = microtime(true);                                                                                                                                
                                                                                                                                                      
$t3 = microtime(true);                                                                                                                                
for ($i = 0; $i < 100000; $i++) {                                                                                                                     
    if (isset($t->config['config']['debug'])) {                                                                                                       
        $k = $t->config['config']['debug'] + 1;                                                                                                       
    }                                                                                                                                                 
}                                                                                                                                                     
$t4 = microtime(true);                                                                                                                                
                                                                                                                                                      
echo sprintf("%.5f %.5f\n", $t2 - $t1, $t4 - $t3);                                                                                                    
                                                                                                                                                      
?>
======================

Gives:
0.16026 0.06486

Difference is 2.66 times on 100000 iterations or 0.000026 times for a single use.

I went further and ran a profiler. 69.72 of time was spent in the first part and 30.23 in the second, which gives 2.33 times.

isset() is faster but not significantly faster.

-- 
Dmitry Dulepov
TYPO3 Core team
Latest article: http://typo3bloke.net/post-details/do_not_ask_more_than_you_need/
More about TYPO3: http://typo3bloke.net/
Subscribe: http://typo3bloke.net/rss.xml


More information about the TYPO3-team-core mailing list