// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestMain {
    private final static int N = 1000000;
    public static void testCsv() throws TestException, IOException {
        long t1 = System.currentTimeMillis();
        Test tst1 = new CsvTest(new FileOutputStream("C:\\z.dat"));
        tst1.testWrite(N);
        tst1.close();
        long t2 = System.currentTimeMillis();
        Test tst2 = new CsvTest(new FileInputStream("C:\\z.dat"));
        tst2.testRead(N);
        tst2.close();
        long t3 = System.currentTimeMillis();
        long dt12 = t2 - t1;
        long dt23 = t3 - t2;
        long fs = (new File("C:\\z.dat")).length();
        System.out.println("Write: " + dt12 + " (" + fs/dt12 + " KB/s) Read: " + dt23+ " (" + fs/dt23 + " KB/s)");
        fs = (new File("C:\\z.dat")).length() - 4 * N;
        System.out.println("Write: " + dt12 + " (" + fs/dt12 + " KB/s) Read: " + dt23+ " (" + fs/dt23 + " KB/s)");
    }
    public static void testXml() throws TestException, IOException {
        long t1 = System.currentTimeMillis();
        Test tst1 = new XmlTest(new FileOutputStream("C:\\z.xml"));
        tst1.testWrite(N);
        tst1.close();
        long t2 = System.currentTimeMillis();
        Test tst2 = new XmlTest(new FileInputStream("C:\\z.xml"));
        tst2.testRead(N);
        tst2.close();
        long t3 = System.currentTimeMillis();
        long dt12 = t2 - t1;
        long dt23 = t3 - t2;
        long fs = (new File("C:\\z.xml")).length();
        System.out.println("Write: " + dt12 + " (" + fs/dt12 + " KB/s) Read: " + dt23+ " (" + fs/dt23 + " KB/s)");
        fs = (new File("C:\\z.dat")).length() - 4 * N;
        System.out.println("Write: " + dt12 + " (" + fs/dt12 + " KB/s) Read: " + dt23+ " (" + fs/dt23 + " KB/s)");
    }
    public static void main(String[] args) throws TestException, IOException {
        testCsv();
        testXml();
    }
}
