[TYPO3-core] Interesting...

Kasper Skårhøj kasper2006 at typo3.com
Sun Mar 19 20:40:17 CET 2006


Thanks Johannes,

Yes, that is an interesting benchmark. I don't know how hard TYPO3  
might be affected by it. Generally I guess the work on version 5.0  
will also entertain some similar tests of how large objects will or  
will not slow down TYPO3 in a new architecture. Therefore I put TYPO3  
core team in copy (For their information)...

- kasper

	
On Mar 18, 2006, at 17:17 , Johannes Reichardt wrote:

> Hi Kasper!
>
> Hope you´re doing good! I just surfed by a comment on php.net i  
> want to show you - i don´t really know if its valuable for typo3  
> but it sounds quite interesting regarding php performance and  
> $variables.
>
> - Johannes
>
> <Snip from http://de.php.net/static>
>
>
> I've been doing some performance tests. I thought I could squeeze  
> some extra cyles using references, but I discovered they are more  
> mysterious than I imagined (5.0.3).
>
> Consider this:
>
> $a = str_repeat('hola',10000000);
> for($n = 0 ; $n < 1000000 ; $n++ ) { $b = $a; unset($b); }
>
> real    0m1.514s
> user    0m1.433s
> sys    0m0.071s
>
> The above times (as others in this note) are the best out of three  
> attempts in an idle Linux box.
>
> I expected the above to be a bit slow, since constructing $b might  
> imply copying the 40MB string each time. It was very fast, though.  
> Let's try with references:
>
> $a = str_repeat('hola',10000000);
> for($n = 0 ; $n < 1000000 ; $n++ ) { $b =& $a; unset($b); }
>
> real    0m1.488s
> user    0m1.380s
> sys    0m0.071s
>
> Not much of a gain, but it did took less time to complete. Will  
> this work with functions? Let's see:
>
> $a = str_repeat('hola',10000000);
> for($n = 0 ; $n < 1000000 ; $n++ ) dosome($a);
> function dosome($arg){ $t = strlen($arg); }
>
> real    0m3.518s
> user    0m3.276s
> sys    0m0.088s
>
> Mmm... much slower, but still pretty nice. I didn't use references  
> yet, so let's try them out:
>
> $a = str_repeat('hola',10000000);
> for($n = 0 ; $n < 100 ; $n++ ) dosome($a);
> function dosome(&$arg){ $t = strlen($arg); }
>
> real    0m12.071s
> user    0m6.190s
> sys    0m5.821s
>
> You think it is 3.5 times slower? Think again. It is 350,000 times  
> slower. I had to limit the $n loop to 100 iterations in order to  
> get those figures! I wonder what happens if I try to access the  
> variable globally:
>
> $a = str_repeat('hola',10000000);
> for($n = 0 ; $n < 1000000 ; $n++ ) dosome();
> function dosome(){ $t = strlen($GLOBALS['a']); }
>
> real    0m3.007s
> user    0m2.918s
> sys    0m0.074s
>
> Notice that using $GLOBALS we're back in bussiness. So using the  
> global keyword should be exactly the same, isn't it? Wrong again:
>
> $a = str_repeat('hola',10000000);
> for($n = 0 ; $n < 100 ; $n++ ) dosome();
> function dosome(){ global $a; $t = strlen($a); }
>
> real    0m12.423s
> user    0m6.112s
> sys    0m5.917s
>
> We're in the '350,000 times slower' domain again. I wonder why the  
> script is spending so much time in sys.
>
> A couple of additional tests to complete the puzzle:
>
> $a = str_repeat('hola',10000000); $b = Array(&$a);
> for($n = 0 ; $n < 100 ; $n++ ) dosome();
> function dosome(){ $t = strlen($GLOBALS['b'][0]); }
>
> real    0m12.087s
> user    0m6.068s
> sys    0m5.955s
>
> $a = str_repeat('hola',10000000); $b = Array(&$a);
> for($n = 0 ; $n < 100 ; $n++ ) dosome();
> function dosome(){ global $b; $t = strlen($b[0]); }
>
> real    0m12.158s
> user    0m6.023s
> sys    0m5.971s
>
> I guess the $GLOBALS trick doesn't help when we access a reference  
> stored in the global variable.
>
> I'm completely confused, now. At this light, I will review my usage  
> of the global keyword as well as for the references. I hope someone  
> can benefit from this study too.


- kasper

"A contribution a day keeps the fork away"
-------------------------------
kasper2006 at typo3.com | +45 20 999 115 | skype: kasperskaarhoej |  
gizmo: kasper_typo3





More information about the TYPO3-team-core mailing list