X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D1F5754213 for ; Thu, 28 Apr 2005 01:22:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 72952-08 for ; Thu, 28 Apr 2005 04:22:33 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id F396F54208 for ; Thu, 28 Apr 2005 01:22:31 -0300 (ADT) Received: from flood.opencloud.co.nz ([192.168.0.31]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1DR0Xl-0003UW-3F; Thu, 28 Apr 2005 16:22:29 +1200 Message-ID: <42706503.7080800@opencloud.com> Date: Thu, 28 Apr 2005 16:22:27 +1200 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Gnanavel S Cc: pgsql-jdbc@postgresql.org Subject: Re: Performance of loop References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/187 X-Sequence-Number: 12794 Gnanavel S wrote: > In the above coding, say if the length of the query is 1000 characters > then the query.length() is evaluated 1000 times there by reducing the > performance. > I think the loop can be rewritten as > > for (int i = 0,c=query.length(); i < c; ++i) > { > char c = query.charAt(i); > > .... > ..... > } Have you benchmarked this? I doubt it's really a hotspot given that the JIT is likely to inline length(). Premature optimization and all that.. -O