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 465955420E for ; Thu, 28 Apr 2005 01:39:07 -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 78912-08 for ; Thu, 28 Apr 2005 04:39:00 +0000 (GMT) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.206]) by svr1.postgresql.org (Postfix) with ESMTP id 0371054224 for ; Thu, 28 Apr 2005 01:38:59 -0300 (ADT) Received: by zproxy.gmail.com with SMTP id 34so738553nzf for ; Wed, 27 Apr 2005 21:38:59 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:references; b=eNthwHarL8ddA3jswT/6uCUc/eNL9NIiDbKg6+QIuC0h0txUhPFz2YEN5mk8DcfH9WV37sCx2+FqWyI76yHNYzs4NB4lNr7ScDEl7oO610oyrRAgaHY6eF93rT9uFEoxH4FWH8m8KTQh+uhXK21ro/qcm+OZ9GDJUo1+XG5oLi4= Received: by 10.36.9.12 with SMTP id 12mr80125nzi; Wed, 27 Apr 2005 21:38:59 -0700 (PDT) Received: by 10.36.60.12 with HTTP; Wed, 27 Apr 2005 21:38:59 -0700 (PDT) Message-ID: Date: Thu, 28 Apr 2005 10:08:59 +0530 From: Gnanavel S Reply-To: Gnanavel S To: Oliver Jowett Subject: Re: Performance of loop Cc: pgsql-jdbc@postgresql.org In-Reply-To: <42706503.7080800@opencloud.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_8554_4490694.1114663139031" References: <42706503.7080800@opencloud.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.586 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, HTML_30_40, HTML_MESSAGE, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200504/188 X-Sequence-Number: 12795 ------=_Part_8554_4490694.1114663139031 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline No. I havn't done any benchmark, but lot of such inefficient loops may hit= =20 the performance. On 4/28/05, Oliver Jowett wrote: >=20 > Gnanavel S wrote: >=20 > > 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 =3D 0,c=3Dquery.length(); i < c; ++i) > > { > > char c =3D query.charAt(i); > > > > .... > > ..... > > } >=20 > 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.. >=20 > -O >=20 --=20 with regards, S.Gnanavel Satyam Computer Services Ltd. ------=_Part_8554_4490694.1114663139031 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline No. I havn't done any benchmark, but lot of such inefficient loops may hit = the performance.

On 4/28/05, Oliver Jowett < oliver@opencloud.com> wrote:
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 rewritt= en as
>
> for (int i =3D 0,c=3Dquery.length(); i < c; ++i)> {
> char c =3D query.charAt(i);
>
> ....
> .....
>= }

Have you benchmarked this? I doubt it's really a hotspot given th= at the
JIT is likely to inline length(). Premature optimization and all = that..

-O



--
with regards,
S.Gnan= avel
Satyam Computer Services Ltd. ------=_Part_8554_4490694.1114663139031--