private double test(StreamTester tester, int numberOfTests) throws IOException { double duration = 0d; for (int i = 0; i < numberOfTests; i++) { long start = System.nanoTime(); tester.doTest(); duration += (double) (System.nanoTime() - start); } return duration / 1.0e9; }
public static void main(String[] args) throws IOException { StreamsPerfTest perfTest = new StreamsPerfTest(); PrintWriter console = new PrintWriter(System.out, true); print("temp file:" + TEMP_FILE_NAME); print("initial file contains " + FILE_CONTENT.length() + " characters"); print("initial file contains " + FILE_CONTENT_LIST.size() + " rows"); print("-------------------------------------------"); String formatPattern = "%1$30s : %2$-10.4f s\n"; print("1. test 10 attempts:"); for (StreamTester tester : TESTERS) console.printf(formatPattern, tester.getName(), perfTest.test(tester, 10)); print("-------------------------------------------"); print("2. test 100 attempts:"); for (StreamTester tester : TESTERS) console.printf(formatPattern, tester.getName(), perfTest.test(tester, 100)); print("-------------------------------------------"); print("3. test 200 attempts:"); for (StreamTester tester : TESTERS) console.printf(formatPattern, tester.getName(), perfTest.test(tester, 200)); print("-------------------------------------------"); }