CSV-286: Cleanup and Document Performance Test Harness (#170)

This commit is contained in:
belugabehr 2021-07-19 16:39:29 -04:00 committed by GitHub
parent 27843d8dc0
commit 0453989efe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

@ -72,3 +72,8 @@ mvn test -Dtest=PerformanceTest
``` ```
> :warning: This performance test does not use JMH; it uses simple timing metrics. > :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`

View File

@ -37,8 +37,6 @@ import org.apache.commons.io.IOUtils;
/** /**
* Basic test harness. * Basic test harness.
*
* Requires test file to be downloaded separately.
*/ */
@SuppressWarnings("boxing") @SuppressWarnings("boxing")
public class PerformanceTest { public class PerformanceTest {
@ -68,20 +66,21 @@ public class PerformanceTest {
private static final CSVFormat format = CSVFormat.EXCEL; 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 { public static void main(final String [] args) throws Exception {
if (BIG_FILE.exists()) { if (BIG_FILE.exists()) {
System.out.printf("Found test fixture %s: %,d bytes.%n", BIG_FILE, BIG_FILE.length()); System.out.printf("Found test fixture %s: %,d bytes.%n", BIG_FILE, BIG_FILE.length());
} else { } else {
final File compressedFile = new File(BIG_FILE.getParentFile(), BIG_FILE.getName() + ".gz"); System.out.println("Decompressing test fixture to: " + BIG_FILE + "...");
System.out.printf("Decompressing test fixture %s...%n", compressedFile); try (
long bytesOut = 0L; final InputStream input = new GZIPInputStream(
try (final InputStream input = new GZIPInputStream(new FileInputStream(compressedFile)); PerformanceTest.class.getClassLoader().getResourceAsStream(TEST_RESRC));
final OutputStream output = new FileOutputStream(BIG_FILE)) { final OutputStream output = new FileOutputStream(BIG_FILE)) {
bytesOut = IOUtils.copy(input, output); IOUtils.copy(input, output);
} System.out.println(String.format("Decompressed test fixture %s: %,d bytes.", BIG_FILE, BIG_FILE.length()));
System.out.printf("Decompressed test fixture %s: %,d bytes to: %s: %,d bytes.%n", compressedFile, compressedFile.length(), BIG_FILE, bytesOut); }
} }
final int argc = args.length; final int argc = args.length;
if (argc > 0) { if (argc > 0) {