pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: Stephen Denne <Stephen.Denne@datamail.co.nz>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Minor performance improvements
Date: Tue, 27 Feb 2007 03:21:25 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0702270319360.11284@leary.csoft.net> (raw)
In-Reply-To: <Pine.BSO.4.64.0702262316480.1687@leary.csoft.net>
References: <F0238EBA67824444BC1CB4700960CB4802540178@dmpeints002.isotach.com>
	<Pine.BSO.4.64.0702262316480.1687@leary.csoft.net>



On Mon, 26 Feb 2007, Kris Jurka wrote:

> I've created the attached test which tests the original code (Orig), your 
> code (Two), and my suggestion of an int4buf (Three) and got the following 
> surprising results:
>

Based on that test and a similar attached test for reading, I'm prepared 
to apply the attached patch.  Let me know what you think.

Kris Jurka

Attachments:

Read.java (text/plain, 1.9K) download import java.io.*; public class Read { public static void main(String args[]) throws Exception { if (args.length != 1) { System.err.println("Usage: java Read <impl>"); System.exit(1); } Class c = Class.forName(args[0]); Test t = (Test)c.newInstance(); for (int i=0; i<5; i++) { t.test(); } t.close(); } } abstract class Test { protected InputStream pg_input; Test() throws IOException { pg_input = new BufferedInputStream(new FileInputStream("/dev/zero"), 8192); } void close() throws IOException { pg_input.close(); } void test() throws IOException { long start = System.currentTimeMillis(); for (int i=0; i<100000000; i++) { ReceiveIntegerR(4); } long stop = System.currentTimeMillis(); System.out.println(stop - start); } protected abstract int ReceiveIntegerR(int siz) throws IOException; } class Orig extends Test { Orig() throws IOException { } protected int ReceiveIntegerR(int siz) throws IOException { int n = 0; for (int i = 0 ; i < siz ; i++) { int b = pg_input.read() & 0xFF; n = b | (n << 8); } switch (siz) { case 1: return (int)((byte)n); case 2: return (int)((short)n); default: return n; } } } class Two extends Test { Two() throws IOException { } protected int ReceiveIntegerR(int siz) throws IOException { int n = pg_input.read() & 0xFF; n = pg_input.read() | (n << 8); n = pg_input.read() | (n << 8); n = pg_input.read() | (n << 8); return n; } } class Three extends Test { private byte[] intbuf; Three() throws IOException { intbuf = new byte[4]; } protected int ReceiveIntegerR(int siz) throws IOException { pg_input.read(intbuf); return (intbuf[0] & 0xFF) << 24 | (intbuf[1] & 0xFF) << 16 | (intbuf[2] & 0xFF) << 8 | intbuf[3] & 0xFF; } }
pgstream-perf.patch.gz (application/octet-stream, 4.4K) download

view thread (11+ messages)  latest in thread

Message-ID: <Pine.BSO.4.64.0702270319360.11284@leary.csoft.net>
Permalink:  ../Pine.BSO.4.64.0702270319360.11284@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.64.0702270319360.11284@leary.csoft.net

 · 

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: books@ejurka.com, Stephen.Denne@datamail.co.nz
  Subject: Re: Minor performance improvements
  In-Reply-To: <Pine.BSO.4.64.0702270319360.11284@leary.csoft.net>
  References: <F0238EBA67824444BC1CB4700960CB4802540178@dmpeints002.isotach.com> <Pine.BSO.4.64.0702262316480.1687@leary.csoft.net> <Pine.BSO.4.64.0702270319360.11284@leary.csoft.net>

* 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