Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit 883a0e9

Browse files
committed
Allow performance test to traverse column values (optional).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1397559 13f79535-47bb-0310-9956-ffa450edef68
1 parent 53fd86d commit 883a0e9

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.zip.GZIPInputStream;
3131

3232
import org.apache.commons.csv.CSVFormat;
33+
import org.apache.commons.csv.CSVRecord;
3334
import org.apache.commons.io.IOUtils;
3435
import org.junit.BeforeClass;
3536
import org.junit.Ignore;
@@ -64,13 +65,18 @@ private BufferedReader getBufferedReader() throws IOException {
6465
return new BufferedReader(new FileReader(BIG_FILE));
6566
}
6667

67-
private long parse(final Reader in) throws IOException {
68+
private long parse(final Reader in, boolean traverseColumns) throws IOException {
6869
final CSVFormat format = CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(false);
69-
long count = 0;
70-
for (final Object record : format.parse(in)) {
71-
count++;
70+
long recordCount = 0;
71+
for (final CSVRecord record : format.parse(in)) {
72+
recordCount++;
73+
if (traverseColumns) {
74+
for (String value : record) {
75+
// do nothing for now
76+
}
77+
}
7278
}
73-
return count;
79+
return recordCount;
7480
}
7581

7682
private void println() {
@@ -89,9 +95,9 @@ private long readAll(final BufferedReader in) throws IOException {
8995
return count;
9096
}
9197

92-
public long testParseBigFile() throws Exception {
98+
public long testParseBigFile(boolean traverseColumns) throws Exception {
9399
final long startMillis = System.currentTimeMillis();
94-
final long count = this.parse(this.getBufferedReader());
100+
final long count = this.parse(this.getBufferedReader(), traverseColumns);
95101
final long totalMillis = System.currentTimeMillis() - startMillis;
96102
this.println(String.format("File parsed in %,d milliseconds with Commons CSV: %,d lines.", totalMillis, count));
97103
return totalMillis;
@@ -101,7 +107,7 @@ public long testParseBigFile() throws Exception {
101107
public void testParseBigFileRepeat() throws Exception {
102108
long bestTime = Long.MAX_VALUE;
103109
for (int i = 0; i < this.max; i++) {
104-
bestTime = Math.min(this.testParseBigFile(), bestTime);
110+
bestTime = Math.min(this.testParseBigFile(false), bestTime);
105111
}
106112
this.println(String.format("Best time out of %,d is %,d milliseconds.", this.max, bestTime));
107113
}

0 commit comments

Comments
 (0)