Hi all
I'd like to ask you if there's a significant difference in performance between:
PrintWriter out = response.getWriter(); String ret = ""; for (count = 0; rs.next(); count++) ret += rs.getString("column_name"); // result of db query out.print(ret); out.close();
Use a StringBuffer when looping and then do buffer.toString() after the loop. Make sure to size the StringBuffer to a reasonable size for what you expect. Resizing a StringBuffer to hold more string information is very expensive. Concatenation will create a new StringBuffer for every concatenation. Very low performance!
This should make the code above similar in performance to the code below
Jake
and:
PrintWriter out = response.getWriter(); for (count = 0; rs.next(); count++) out.print(rs.getString("column_name"); // result of db query out.close();
I know I have the extra string which is (theoretically) a slow-down but I don't
know anything about the way how tomcat handles with large strings (in my case about 1MB), if is there any limited buffering etc.
I know as well I can test it by myself very easilly but I hope someone's gonna give me a bit of explanation along with 20 funny stories etc. :)
EOF & thx
Bost
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]