pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Migowski <dmigowski@ikoffice.de>
To: pgsql-jdbc@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Oliver Jowett <oliver@opencloud.com>
Cc: Gregory Stark <stark@enterprisedb.com>
Cc: Kris Jurka <books@ejurka.com>
Subject: Re: TypeInfoCache
Date: Thu, 27 Dec 2007 09:40:02 +0100
Message-ID: <477364E2.2010808@ikoffice.de> (raw)
In-Reply-To: <476A9083.80407@ikoffice.de>
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>

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

Attachments:

StringVsStreamTest.java (text/plain, 2.9K) download 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)); } }

view thread (32+ messages)  latest in thread

Message-ID: <477364E2.2010808@ikoffice.de>
Permalink:  ../477364E2.2010808@ikoffice.de/
Also on:    postgresql.org/message-id/477364E2.2010808@ikoffice.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: dmigowski@ikoffice.de, tgl@sss.pgh.pa.us, oliver@opencloud.com, stark@enterprisedb.com, books@ejurka.com
  Subject: Re: TypeInfoCache
  In-Reply-To: <477364E2.2010808@ikoffice.de>
  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> <477364E2.2010808@ikoffice.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox