The second has a better chance at being faster.
Way number 1 can create one huge memory wasting buffer. Evern worse - an extra String (and StringBuffer) is created on every loop iteration resulting lots of potential/wasted gc work.
-Tim
Rostislav Svoboda wrote:
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(); 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. :)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]