Return-Path: Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 1506 invoked from network); 18 Feb 2003 18:00:21 -0000 Received: from virus-out.ttyl.com (193.212.240.200) by daedalus.apache.org with SMTP; 18 Feb 2003 18:00:21 -0000 Received: from [80.212.8.187] by virus-in.online.no with ESMTP for commons-user@jakarta.apache.org; Tue, 18 Feb 2003 19:00:22 +0100 Message-Id: <3E527487.6@altern.org> Date: Tue, 18 Feb 2003 18:59:35 +0100 From: "Jerome Lacoste @ BBC" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en, en-us MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: StringBuffer pools and why not to use them References: <0C072E7CC947D511AC9600A0CC734120885E2B@XEON400> <005001c2d76c$a542bf50$8dfb0d50@zzz> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Robert Simmons wrote: >Well now ... I think this post goes a bit far. At least he tried the task before >advocating it. The fact is that a large number of people poorly use StringBuffer >anyway. This could account for performance hits. The simple line of code that >you see all the time like: > >StringBuffer buf = new StringBuffer(500); >buf.append("This is a test under " + System.getProperty("os.arch") + > " operating system, version " + >System.getProperty("os.version")); > >This code has a serious problem. Since you are so busy calling others idiots, >can you tell us all why ? > There are two bad things: - too much allocation - no use of the append() methods Both make the calls slower. On my machine, reducing the size of the StringBuffer to 80 (*) helps as much as using append() correctly. (*) could have used a different value there. Just knowing that doMe() returns a String of length 54 on my VM Looping 100000 times around a call to these methods public static String doMe() { StringBuffer buf = new StringBuffer(500); buf.append("This is a test under " + System.getProperty("os.arch") + " operating system, version " + System.getProperty("os.version")); return buf.toString(); } public static String doMeBetter() { StringBuffer buf = new StringBuffer(500); buf.append("This is a test under ").append(System.getProperty("os.arch")); buf.append(" operating system, version ").append(System.getProperty("os.version")); return buf.toString(); } public static String doMeEvenBetter() { StringBuffer buf = new StringBuffer(80); buf.append("This is a test under ").append(System.getProperty("os.arch")); buf.append(" operating system, version ").append(System.getProperty("os.version")); return buf.toString(); } Results: DoMe() count: 4500 DoMeBetter() count: 3234 DoMeEvenBetter() count: 1704 DoMe() count: 4500 DoMeBetter() count: 3218 DoMeEvenBetter() count: 1703 DoMe() count: 4563 DoMeBetter() count: 3203 DoMeEvenBetter() count: 1734 >-- Robert > >"Chris Duprat" wrote in message >news:005001c2d76c$a542bf50$8dfb0d50@zzz... > > >>Wasting of time. You shouldn't have the idea of implementing a pool for such >>objects because of their high availability. By adding another level you just >>reach the performance issue which is critical for that kind of objects. >> >>You're an Idiot ;-) >>http://www.pagetutor.com/idiot/idiot.html >> BTW, click on on the page anywhere, drag your mouse over the button and release click at once to win ;)