| From: | Alex Malone <amalone(at)heliumsystems(dot)com> | 
|---|---|
| To: | pgsql-jdbc(at)postgresql(dot)org | 
| Subject: | TimestampUtils.toString() speedup | 
| Date: | 2007-03-02 17:03:54 | 
| Message-ID: | 129448.5111.qm@web32909.mail.mud.yahoo.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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();
    }
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Kris Jurka | 2007-03-02 18:01:13 | Re: TimestampUtils.toString() speedup | 
| Previous Message | aaabdallah | 2007-03-02 08:22:44 | Re: Inserting "null" not working (Sun App Server, Postgres, EJB3)? |