Peter Royal a écrit :
>
> On Wednesday 05 December 2001 10:36 am, Tom Klaasen (TeleRelay) wrote:
> > Use StringBuffers. Check for log.isDebugEnabled(). Especially in loops.
> > In May, this speeded up our application from 1s to 0.1s for certain
> > pages (a speedup of euh... has anyone studied advanced math? ;) )
>
> And be sure to set reloadable=false for the context in tomcat!
>
> When you mention use StringBuffers, is it better to do
>
> StringBuffer sb = new StringBuffer();
>
> return sb.append("this").append("is").append("a string");
>
> rather than
>
> return "this" + "is" + "a string";
>
> ?
>
> I was under the impression that the compiler would optimize the second case.
> I do know to use a StringBuffer when in a loop that you're appending to a
> string in tho :)
> -pete
>
> --
> peter royal -> [EMAIL PROTECTED]
I studied in detail the generated byte code for both types and came to
the conclusion that using StringBuffer is only useful when the string is
built in separate statements (such as in a loop). For more details, see
:
http://marc.theaimsgroup.com/?l=xml-cocoon-dev&m=100413627531535&w=2
BTW, using isDebugEnabled() is only useful if the message is a
concatenation of strings. If it's a static string, it can even be slower
if debug is enabled because of the double check !
Sylvain
--
Sylvain Wallez
Anyware Technologies - http://www.anyware-tech.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]