Skip to content

Commit 0453989

Browse files
authored
CSV-286: Cleanup and Document Performance Test Harness (apache#170)
1 parent 27843d8 commit 0453989

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

BENCHMARK.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@ mvn test -Dtest=PerformanceTest
7272
```
7373

7474
> :warning: This performance test does not use JMH; it uses simple timing metrics.
75+
76+
Performance Test Harness
77+
-------------
78+
79+
CSV offers a secondary performance test harness located at: `org.apache.commons.csv.PerformanceTest`

src/test/java/org/apache/commons/csv/PerformanceTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737

3838
/**
3939
* Basic test harness.
40-
*
41-
* Requires test file to be downloaded separately.
4240
*/
4341
@SuppressWarnings("boxing")
4442
public class PerformanceTest {
@@ -68,20 +66,21 @@ public class PerformanceTest {
6866

6967
private static final CSVFormat format = CSVFormat.EXCEL;
7068

71-
private static final File BIG_FILE = new File("src/test/resources/perf/worldcitiespop.txt");
69+
private static final String TEST_RESRC = "org/apache/commons/csv/perf/worldcitiespop.txt.gz";
70+
private static final File BIG_FILE = new File(System.getProperty("java.io.tmpdir"), "worldcitiespop.txt");
7271

7372
public static void main(final String [] args) throws Exception {
7473
if (BIG_FILE.exists()) {
7574
System.out.printf("Found test fixture %s: %,d bytes.%n", BIG_FILE, BIG_FILE.length());
7675
} else {
77-
final File compressedFile = new File(BIG_FILE.getParentFile(), BIG_FILE.getName() + ".gz");
78-
System.out.printf("Decompressing test fixture %s...%n", compressedFile);
79-
long bytesOut = 0L;
80-
try (final InputStream input = new GZIPInputStream(new FileInputStream(compressedFile));
81-
final OutputStream output = new FileOutputStream(BIG_FILE)) {
82-
bytesOut = IOUtils.copy(input, output);
83-
}
84-
System.out.printf("Decompressed test fixture %s: %,d bytes to: %s: %,d bytes.%n", compressedFile, compressedFile.length(), BIG_FILE, bytesOut);
76+
System.out.println("Decompressing test fixture to: " + BIG_FILE + "...");
77+
try (
78+
final InputStream input = new GZIPInputStream(
79+
PerformanceTest.class.getClassLoader().getResourceAsStream(TEST_RESRC));
80+
final OutputStream output = new FileOutputStream(BIG_FILE)) {
81+
IOUtils.copy(input, output);
82+
System.out.println(String.format("Decompressed test fixture %s: %,d bytes.", BIG_FILE, BIG_FILE.length()));
83+
}
8584
}
8685
final int argc = args.length;
8786
if (argc > 0) {

0 commit comments

Comments
 (0)