From 0453989efe8629ecb5a2839da056b4ccc3451b18 Mon Sep 17 00:00:00 2001 From: belugabehr <12578579+belugabehr@users.noreply.github.com> Date: Mon, 19 Jul 2021 16:39:29 -0400 Subject: [PATCH] CSV-286: Cleanup and Document Performance Test Harness (#170) --- BENCHMARK.md | 5 +++++ .../apache/commons/csv/PerformanceTest.java | 21 +++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/BENCHMARK.md b/BENCHMARK.md index 67569ead..e8b579b2 100644 --- a/BENCHMARK.md +++ b/BENCHMARK.md @@ -72,3 +72,8 @@ mvn test -Dtest=PerformanceTest ``` > :warning: This performance test does not use JMH; it uses simple timing metrics. + +Performance Test Harness +------------- + +CSV offers a secondary performance test harness located at: `org.apache.commons.csv.PerformanceTest` diff --git a/src/test/java/org/apache/commons/csv/PerformanceTest.java b/src/test/java/org/apache/commons/csv/PerformanceTest.java index a9dcca01..84ed0837 100644 --- a/src/test/java/org/apache/commons/csv/PerformanceTest.java +++ b/src/test/java/org/apache/commons/csv/PerformanceTest.java @@ -37,8 +37,6 @@ import org.apache.commons.io.IOUtils; /** * Basic test harness. - * - * Requires test file to be downloaded separately. */ @SuppressWarnings("boxing") public class PerformanceTest { @@ -68,20 +66,21 @@ public class PerformanceTest { private static final CSVFormat format = CSVFormat.EXCEL; - private static final File BIG_FILE = new File("src/test/resources/perf/worldcitiespop.txt"); + private static final String TEST_RESRC = "org/apache/commons/csv/perf/worldcitiespop.txt.gz"; + private static final File BIG_FILE = new File(System.getProperty("java.io.tmpdir"), "worldcitiespop.txt"); public static void main(final String [] args) throws Exception { if (BIG_FILE.exists()) { System.out.printf("Found test fixture %s: %,d bytes.%n", BIG_FILE, BIG_FILE.length()); } else { - final File compressedFile = new File(BIG_FILE.getParentFile(), BIG_FILE.getName() + ".gz"); - System.out.printf("Decompressing test fixture %s...%n", compressedFile); - long bytesOut = 0L; - try (final InputStream input = new GZIPInputStream(new FileInputStream(compressedFile)); - final OutputStream output = new FileOutputStream(BIG_FILE)) { - bytesOut = IOUtils.copy(input, output); - } - System.out.printf("Decompressed test fixture %s: %,d bytes to: %s: %,d bytes.%n", compressedFile, compressedFile.length(), BIG_FILE, bytesOut); + System.out.println("Decompressing test fixture to: " + BIG_FILE + "..."); + try ( + final InputStream input = new GZIPInputStream( + PerformanceTest.class.getClassLoader().getResourceAsStream(TEST_RESRC)); + final OutputStream output = new FileOutputStream(BIG_FILE)) { + IOUtils.copy(input, output); + System.out.println(String.format("Decompressed test fixture %s: %,d bytes.", BIG_FILE, BIG_FILE.length())); + } } final int argc = args.length; if (argc > 0) {