|
Home > Archive > PostgreSQL JDBC > April 2005 > Performance of loop
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Performance of loop
|
|
| Gnanavel S 2005-04-28, 3:24 am |
| Hi,
First of all, I would like to thank the postgresql team for providing this
wonderful product.
Coming to the point, in postgresql jdbc driver coding, I saw many
inefficient "for" loops. For eg in V2Query.class file
While parsing the parameterized query, there is a "for" loop as this
for (int i = 0; i < query.length(); ++i)
{
char c = query.charAt(i);
.....
......
}
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);
.....
......
}
with regards,
S.Gnanavel
Software Engineer
Satyam Computer Services Ltd
| |
| Oliver Jowett 2005-04-28, 3:24 am |
| 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
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
| |
| Gnanavel S 2005-04-28, 3:24 am |
| 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:
>
>
> 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
>
--
with regards,
S.Gnanavel
Satyam Computer Services Ltd.
|
|
|
|
|