pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
TimestampUtils.toString() speedup
3+ messages / 2 participants
[nested] [flat]

* TimestampUtils.toString() speedup
@ 2007-03-02 17:03  Alex Malone <amalone@heliumsystems.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Alex Malone @ 2007-03-02 17:03 UTC (permalink / raw)
  To: pgsql-jdbc

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.

    public static final SimpleDateFormat pgdtf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ GG");
    private static final FieldPosition FIRSTPOS = new FieldPosition(0);
    
    public synchronized String toString(Calendar cal, Timestamp x) {
        if (cal == null)
            cal = defaultCal;

        cal.setTime(x);
        sbuf.setLength(0);

        if (x.getTime() == PGStatement.DATE_POSITIVE_INFINITY) {
            sbuf.append("infinity");
        } else if (x.getTime() == PGStatement.DATE_NEGATIVE_INFINITY) {
            sbuf.append("-infinity");
        } else {

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

            /*
            appendDate(sbuf, cal);
            sbuf.append(' ');
            appendTime(sbuf, cal, x.getNanos());
            appendTimeZone(sbuf, cal);
            appendEra(sbuf, cal);
            */
        }

        showString("timestamp", cal, x, sbuf.toString());
        return sbuf.toString();
    }




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: TimestampUtils.toString() speedup
@ 2007-03-02 18:01  Kris Jurka <books@ejurka.com>
  parent: Alex Malone <amalone@heliumsystems.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Kris Jurka @ 2007-03-02 18:01 UTC (permalink / raw)
  To: Alex Malone <amalone@heliumsystems.com>; +Cc: pgsql-jdbc



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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: TimestampUtils.toString() speedup
@ 2007-03-02 18:38  Alex Malone <amalone@heliumsystems.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Alex Malone @ 2007-03-02 18:38 UTC (permalink / raw)
  To: pgsql-jdbc

You have a point Kris.  At least in our application, we have a different way of tracking hi-resolution time, and millisecond timestamps are fine.
For general use, an additional substitution with nanoseconds is needed.

--
Doesn't this leave out the nanoseconds?  The Calendar won't have anything 
below milliseconds.

Kris Jurka










^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2007-03-02 18:38 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-03-02 17:03 TimestampUtils.toString() speedup Alex Malone <amalone@heliumsystems.com>
2007-03-02 18:01 ` Kris Jurka <books@ejurka.com>
2007-03-02 18:38 Re: TimestampUtils.toString() speedup Alex Malone <amalone@heliumsystems.com>

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