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: Mon, 26 Feb 2007 23:24:09 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0702262316480.1687@leary.csoft.net> (raw)
In-Reply-To: <F0238EBA67824444BC1CB4700960CB4802540178@dmpeints002.isotach.com>
References: <F0238EBA67824444BC1CB4700960CB4802540178@dmpeints002.isotach.com>
On Tue, 27 Feb 2007, Stephen Denne wrote:
> I'm sad to say that I have not created any micro-benchmark tests, and
> unfortunately the improvements are very minor, and far overshadowed by
> the variability I get from my system.
>
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:
jurka@tony:~/pg/jdbc/projects/perf/micro$ java -classpath . Tester Orig |
sort -n
11335
11370
11468
11484
11487
jurka@tony:~/pg/jdbc/projects/perf/micro$ java -classpath . Tester Two |
sort -n
12472
12476
12489
12492
12619
jurka@tony:~/pg/jdbc/projects/perf/micro$ java -classpath . Tester Three |
sort -n
4259
4562
4564
4611
4689
This shows your code is actually slower than the original code, although I
have no idea why that could be. It shows the int4buf idea as a clear
winner. I'm a little suspicious of the whole test because of your numbers
going up. Could you take a look at this and possibly confirm the results?
I'm not sure if windows has an equivalent to /dev/null, but I wanted to
avoid any impact of disk io.
Kris Jurka
Attachments:Tester.java (text/plain, 1.8K) download
import java.io.*;
public class Tester {
public static void main(String args[]) throws Exception {
if (args.length != 1) {
System.err.println("Usage: java Tester <iml>");
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 OutputStream pg_output;
Test() throws IOException {
pg_output = new BufferedOutputStream(new FileOutputStream("/dev/null"), 8192);
}
void close() throws IOException {
pg_output.close();
}
void test() throws IOException {
long start = System.currentTimeMillis();
for (int i=0; i<100000000; i++) {
SendInteger4(i);
}
long stop = System.currentTimeMillis();
System.out.println(stop - start);
}
protected abstract void SendInteger4(int val) throws IOException;
}
class Orig extends Test {
Orig() throws IOException { }
private void SendChar(int val) throws IOException
{
pg_output.write((byte)val);
}
protected void SendInteger4(int val) throws IOException
{
SendChar((val >> 24)&255);
SendChar((val >> 16)&255);
SendChar((val >> 8)&255);
SendChar(val&255);
}
}
class Two extends Test {
Two() throws IOException { }
protected void SendInteger4(int val) throws IOException
{
pg_output.write(val >> 24);
pg_output.write(val >> 16);
pg_output.write(val >> 8);
pg_output.write(val);
}
}
class Three extends Test {
private byte[] intbuf;
Three() throws IOException {
intbuf = new byte[4];
}
protected void SendInteger4(int val) throws IOException
{
intbuf[0] = (byte)((val >> 24) & 255);
intbuf[1] = (byte)((val >> 16) & 255);
intbuf[2] = (byte)((val >> 8) & 255);
intbuf[3] = (byte)((val) & 255);
pg_output.write(intbuf);
}
}
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.0702262316480.1687@leary.csoft.net>
References: <F0238EBA67824444BC1CB4700960CB4802540178@dmpeints002.isotach.com> <Pine.BSO.4.64.0702262316480.1687@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