Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 4E7542E01BF for ; Thu, 27 Dec 2007 04:40:14 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 41757-07 for ; Thu, 27 Dec 2007 04:40:10 -0400 (AST) Received: from ikoffice.de (ikoffice.de [81.169.166.92]) by postgresql.org (Postfix) with ESMTP id 224062E02AF for ; Thu, 27 Dec 2007 04:40:09 -0400 (AST) Received: from p5481e1cb.dip.t-dialin.net ([84.129.225.203] helo=[192.168.1.16]) by ikoffice.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.66) (envelope-from ) id 1J7oHb-0007cD-LX; Thu, 27 Dec 2007 09:40:05 +0100 Message-ID: <477364E2.2010808@ikoffice.de> Date: Thu, 27 Dec 2007 09:40:02 +0100 From: Daniel Migowski User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org CC: Tom Lane , Oliver Jowett , Gregory Stark , Kris Jurka Subject: Re: TypeInfoCache References: <47692DEB.9070307@ikoffice.de> <877ijan2cp.fsf@oxford.xeocode.com> <47693B10.3040804@ikoffice.de> <873atymzpu.fsf@oxford.xeocode.com> <4769604A.9050006@ikoffice.de> <476989C7.8020307@opencloud.com> <1811.1198113944@sss.pgh.pa.us> <476A4AB7.90509@ikoffice.de> <11679.1198165116@sss.pgh.pa.us> <476A9083.80407@ikoffice.de> In-Reply-To: <476A9083.80407@ikoffice.de> Content-Type: multipart/mixed; boundary="------------030207020207070908090606" X-Spam-Bar: - X-Spam-Score-Int: -17 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200712/178 X-Sequence-Number: 18033 This is a multi-part message in MIME format. --------------030207020207070908090606 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Hello, dear JDBC mailing list members, At first I hope you all had a merry christmas. Regarding the patch I sent, another important argument is this one: I createt a benchmark for getCharacterStream vs. getStream running on a table with a varchar(50) and a text column, each containing 50 chars of data. These are the benchmarks for the differences of calling 1000 times the given function on a Core2Duo 2Ghz and JDK1.5: getString on text_col took 8.27384ms getCharacterStream on text_col took 14.26489ms Factor: 1.724095462324628 getString on varchar_col took 9.57153ms getCharacterStream on varchar_col took 12.76733ms Factor: 1.3338860140437319 Please note only the getString() vs. getCharacterStream()+creatingAString are benchmarked, not the DB connection itself (which is the real bottleneck). And please note only those applications that really use getCharacterStream are a bit slower, but as I explained in my previous mails, they do it for a good reason. Conclusion: There is no real performance loss even in the worst case (which should never occur anyway), so please accept my patch. I wish you all a happy new year! With best regards, Daniel Migowski --------------030207020207070908090606 Content-Type: text/plain; name="StringVsStreamTest.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="StringVsStreamTest.java" package de.ikoffice.jdbc; import java.io.Reader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class StringVsStreamTest { public static void main(String args[]) throws Exception { long nanos; int count; char[] buffer = new char[1000]; long tempNanos1; long tempNanos2; Class.forName("org.postgresql.Driver"); Connection c = DriverManager.getConnection("jdbc:postgresql://192.168.1.3:5432/Test","ik","ik0000"); Statement s = c.createStatement(); ResultSet r = s.executeQuery("SELECT * FROM tbl_test"); r.next(); for( int j = 0; j < 10; j++ ) { // Ignore the times for the first run to be sure no JIT compilation slows us down. for( int i=0; i<1000; i++ ) { String string = r.getString("varchar_col"); } for( int i=0; i<1000; i++ ) { Reader reader = r.getCharacterStream("varchar_col"); count = reader.read(buffer, 0, 1000); String string = new String(buffer,0,count); } for( int i=0; i<1000; i++ ) { String string = r.getString("text_col"); } for( int i=0; i<1000; i++ ) { Reader reader = r.getCharacterStream("text_col"); count = reader.read(buffer, 0, 1000); String string = new String(buffer,0,count); } } // Now do the real measurement. nanos = System.nanoTime(); for( int i=0; i<1000; i++ ) { String string = r.getString("text_col"); } tempNanos1 = System.nanoTime()-nanos; System.out.println("getString on text_col took "+((tempNanos1)/100000d)+"ms"); nanos = System.nanoTime(); for( int i=0; i<1000; i++ ) { Reader reader = r.getCharacterStream("text_col"); count = reader.read(buffer, 0, 1000); String string = new String(buffer,0,count); } tempNanos2 = System.nanoTime()-nanos; System.out.println("getCharacterStream on text_col took "+((tempNanos2)/100000d)+"ms"); System.out.println("Factor: " + (tempNanos2*1d/tempNanos1)); nanos = System.nanoTime(); for( int i=0; i<1000; i++ ) { String string = r.getString("varchar_col"); } tempNanos1 = System.nanoTime()-nanos; System.out.println("getString on varchar_col took "+((tempNanos1)/100000d)+"ms"); nanos = System.nanoTime(); for( int i=0; i<1000; i++ ) { Reader reader = r.getCharacterStream("varchar_col"); count = reader.read(buffer, 0, 1000); String string = new String(buffer,0,count); } tempNanos2 = System.nanoTime()-nanos; System.out.println("getCharacterStream on varchar_col took "+((tempNanos2)/100000d)+"ms"); System.out.println("Factor: " + (tempNanos2*1d/tempNanos1)); } } --------------030207020207070908090606--