Re: [SMARTY] Re: Bugfixes and some other stuff...

From: Date: Sun, 14 Jul 2002 20:52:37 +0000
Subject: Re: [SMARTY] Re: Bugfixes and some other stuff...
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5308@lists.php.net to get a copy of this message
Agreed, it was just my first thought... > Do you think Smarty should attempt to create the top level directory for > $compile_dir or $cache_dir? IMHO, Smarty shouldn't be responsible for > creating these. Normally user "nobody" would not have permission to > create them anyways, they must be setup before hand. Smarty _does_ > create sub-directories, but only in an established directory. This > sounds better to me, this way Smarty isn't blindly trying to create a > new directory somewhere. If you don't have that directory created > already, you don't have Smarty installed properly (or if you do > something dynamic, your application should be responsible for creating it.) *** >My test case shows the opposite: > $var = "foo"; > > for($x=0; $x<100000; $x++) { > switch($foo) { > case "foo1": > case "foo2": > case "foo3": > case "foo4": > case "foo5": > } > } >et cetera. Yes, thats true. You chose "foo" as the string to look for, but "foo" isn't defined in the lookup table. Accessing undefined variables, array values or object properties degrades performance dramatically. With your 5 CASEs (and if-else handling unset values), the following code should always perform better: for($x=0; $x<100000; $x++) { if( isset($_TAGS[$var]) ) { switch($_TAGS[$var]) { case 1: case 2: case 3: case 4: case 5: } } else { //this replaces the default: case } } $var defined in $_TAGS: 0.572s *) $var undefined: 0.284s vs. strcmp (string by string comparision) version: both cases around 0.645s *) *) performance increases the more test CASEs The only useful situation where to use this optimization is inside the Smarty.compiler (main tag processing). Due to the fact that templates are parsed only once, this discussion isn't really important... (silly me ;) To be continued... .SMK.

« previous php.smarty.general (#5308) next »