Milt Epstein wrote:
>
> For example, suppose I do something as innocuous as:
>
> out.println("The value of variableX is " + variableX + "<BR>");
>
> Would it really be worth it to use a StringBuffer for what's being
> output there?
>
> Another alternative would be to use a combination of out.print's and
> out.println's, a la:
>
> out.print("The value of variableX is ");
> out.print(variableX);
> out.println("<BR>");
>
> This gets rid of the concatenation, but at the penalty of additional
> method calls.
Object creation is always more expensive than method invokation. So
the "penalty" here is much much less than the penalty of creating
many objects (or even 1 object).
> I don't want to go crazy with this, I'm just trying to get a handle on
> just how far to go with StringBuffer's. Thanks.
>
I don't know why people are so obsessed with this type of performance
tweaking. It's always better to design things properly , code them
elegantly and keep everything simple. After you do that, if performance
is a problem, then you go and apply all of these techniques and tweak
the hell out of your code.
Most of the time, I don't think you need these optimizations. For
instance
the example you gave with string concat is not bad for stuff that
runs once in a while. But if you were to print that string in a
tight loop (which I doubt) then performance becomes a big issue !!!
- Augusto Sellhorn
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html