From amalone@heliumsystems.com Fri Mar 2 17:10:46 2007 Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id EC9BA9FB796 for ; Fri, 2 Mar 2007 13:10:46 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 62445-09 for ; Fri, 2 Mar 2007 13:10:36 -0400 (AST) X-Greylist: delayed 00:06:40.327907 by SQLgrey-1.7.4 Received: from web32909.mail.mud.yahoo.com (web32909.mail.mud.yahoo.com [209.191.69.109]) by postgresql.org (Postfix) with SMTP id 2CD979FB337 for ; Fri, 2 Mar 2007 13:10:35 -0400 (AST) Received: (qmail 6266 invoked by uid 60001); 2 Mar 2007 17:03:54 -0000 X-YMail-OSG: gK7CauEVM1m8CoA5IuM76k9jLAZFwZRzcaxydmJ9CBd31sGosislv9fEemPjr0M7XyY4joC_VcrYvGJ52BcifOeuVNM6X_Dz4pER0pfDM68jVA-- Received: from [74.93.29.253] by web32909.mail.mud.yahoo.com via HTTP; Fri, 02 Mar 2007 09:03:54 PST X-Mailer: YahooMailRC/468 YahooMailWebService/0.6.132.8 Date: Fri, 2 Mar 2007 09:03:54 -0800 (PST) From: Alex Malone Subject: TimestampUtils.toString() speedup To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-796607518-1172855034=:5111" Message-ID: <129448.5111.qm@web32909.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=BAYES_50, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200703/18 X-Sequence-Number: 16732 --0-796607518-1172855034=:5111 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Here is a small change that improved the performance of setting a timestamp= field on a prepared statement from 0.513ms to 0.083ms in our tests. Measu= red using JProfiler for 50,000 iterations. Essentially it is switching to u= se SimpleDateFormat for toString(). I believe this code is from the 8.1 40= 8 driver.=0A=0A public static final SimpleDateFormat pgdtf =3D new Simpl= eDateFormat("yyyy-MM-dd HH:mm:ssZ GG");=0A private static final FieldPos= ition FIRSTPOS =3D new FieldPosition(0);=0A =0A public synchronized S= tring toString(Calendar cal, Timestamp x) {=0A if (cal =3D=3D null)= =0A cal =3D defaultCal;=0A=0A cal.setTime(x);=0A s= buf.setLength(0);=0A=0A if (x.getTime() =3D=3D PGStatement.DATE_POSI= TIVE_INFINITY) {=0A sbuf.append("infinity");=0A } else if= (x.getTime() =3D=3D PGStatement.DATE_NEGATIVE_INFINITY) {=0A sb= uf.append("-infinity");=0A } else {=0A=0A pgdtf.format(ca= l.getTime(), sbuf, FIRSTPOS);=0A=0A /*=0A appendDate(= sbuf, cal);=0A sbuf.append(' ');=0A appendTime(sbuf, = cal, x.getNanos());=0A appendTimeZone(sbuf, cal);=0A = appendEra(sbuf, cal);=0A */=0A }=0A=0A showString(= "timestamp", cal, x, sbuf.toString());=0A return sbuf.toString();=0A= }=0A=0A=0A --0-796607518-1172855034=:5111 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Here is a small change that improved the performance of setting a= timestamp field on a prepared statement from 0.513ms to 0.083ms in our tes= ts.  Measured using JProfiler for 50,000 iterations. Essentially it is= switching to use SimpleDateFormat for toString().  I believe this cod= e is from the 8.1 408 driver.

    public static final S= impleDateFormat pgdtf =3D new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ GG");<= br>    private static final FieldPosition FIRSTPOS =3D new F= ieldPosition(0);
   
    public synchr= onized String toString(Calendar cal, Timestamp x) {

        if (cal = =3D=3D null)
   &nb= sp;        cal =3D defaultCal;
        cal.setTime(x);
      &nb= sp; sbuf.setLength(0);

     =    if (x.getTime() =3D=3D PGStatement.DATE_POSITIVE_INFINITY) {
            sbuf.= append("infinity");
  &n= bsp;     } else if (x.getTime() =3D=3D PGStatement.DATE= _NEGATIVE_INFINITY) {
  =           sbuf.append("-infini= ty");
    &nbs= p;   } else {

     =        pgdtf.format(cal.getTime(), sbuf, FIRSTPOS);

          = ;  /*

    = ;        appendDate(sbuf, cal);
       =      sbuf.append(' ');
           = appendTime(sbuf, cal, x.getNanos());
         = ;   appendTimeZone(sbuf, cal);
            a= ppendEra(sbuf, cal);
  &= nbsp;         */
        }<= br style=3D"font-family: lucida console,sans-serif;">
        showString("timesta= mp", cal, x, sbuf.toString());
    =     return sbuf.toString();
    }

--0-796607518-1172855034=:5111-- From books@ejurka.com Fri Mar 2 18:01:23 2007 Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id C5BCC9FB7D8 for ; Fri, 2 Mar 2007 14:01:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 43555-08-2 for ; Fri, 2 Mar 2007 14:01:16 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail63.csoft.net (leary.csoft.net [205.205.214.5]) by postgresql.org (Postfix) with SMTP id DD1459FB34E for ; Fri, 2 Mar 2007 14:01:16 -0400 (AST) Received: (qmail 3905 invoked by uid 1112); 2 Mar 2007 18:01:14 -0000 Date: Fri, 2 Mar 2007 13:01:13 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: Alex Malone cc: pgsql-jdbc@postgresql.org Subject: Re: TimestampUtils.toString() speedup In-Reply-To: <129448.5111.qm@web32909.mail.mud.yahoo.com> Message-ID: References: <129448.5111.qm@web32909.mail.mud.yahoo.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.031 tagged_above=0 required=5 tests=AWL, BAYES_50 X-Spam-Level: X-Archive-Number: 200703/19 X-Sequence-Number: 16733 On Fri, 2 Mar 2007, Alex Malone wrote: > Here is a small change that improved the performance of setting a > timestamp field on a prepared statement from 0.513ms to 0.083ms in our > tests. Measured using JProfiler for 50,000 iterations. Essentially it > is switching to use SimpleDateFormat for toString(). I believe this > code is from the 8.1 408 driver. > > pgdtf.format(cal.getTime(), sbuf, FIRSTPOS); Doesn't this leave out the nanoseconds? The Calendar won't have anything below milliseconds. Kris Jurka From amalone@heliumsystems.com Fri Mar 2 18:39:07 2007 Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 102449FB321 for ; Fri, 2 Mar 2007 14:39:07 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 18413-02 for ; Fri, 2 Mar 2007 14:39:00 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from web32907.mail.mud.yahoo.com (web32907.mail.mud.yahoo.com [209.191.69.84]) by postgresql.org (Postfix) with SMTP id 78EB29FB30F for ; Fri, 2 Mar 2007 14:38:59 -0400 (AST) Received: (qmail 54138 invoked by uid 60001); 2 Mar 2007 18:38:57 -0000 X-YMail-OSG: CR0hrA0VM1keFsoNx1qOk2dCoYO9GdlM07d628Y8hGDs8ZBI62ktqegmvH1BO_WA80Bgz5_cUd0riI_TbqnSLqyBayXe6fif1R6TgAKi2RMSQg-- Received: from [74.93.29.253] by web32907.mail.mud.yahoo.com via HTTP; Fri, 02 Mar 2007 10:38:57 PST X-Mailer: YahooMailRC/468 YahooMailWebService/0.6.132.8 Date: Fri, 2 Mar 2007 10:38:57 -0800 (PST) From: Alex Malone Subject: Re: TimestampUtils.toString() speedup To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-930471343-1172860737=:53132" Message-ID: <935964.53132.qm@web32907.mail.mud.yahoo.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.069 tagged_above=0 required=5 tests=AWL, BAYES_50, HTML_50_60, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200703/20 X-Sequence-Number: 16734 --0-930471343-1172860737=:53132 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable You have a point Kris. At least in our application, we have a different wa= y of tracking hi-resolution time, and millisecond timestamps are fine.=0AFo= r general use, an additional substitution with nanoseconds is needed.=0A=0A= --=0ADoesn't this leave out the nanoseconds? The Calendar won't have anyth= ing =0Abelow milliseconds.=0A=0AKris Jurka=0A=0A=0A=0A=0A=0A=0A=0A=0A --0-930471343-1172860737=:53132 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
You have a point Kris.  At least in our application,= we have a different way of tracking hi-resolution time, and millisecond ti= mestamps are fine.
For general use, an additional substitution with nano= seconds is needed.

--
Doesn't this leave out the nanoseconds?&nbs= p; The Calendar won't have anything
below milliseconds.

Kri= s Jurka





--0-930471343-1172860737=:53132--