import java.io.*; public class Tester { public static void main(String args[]) throws Exception { if (args.length != 1) { System.err.println("Usage: java Tester "); 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); } }