From 883a0e91cf5dfb1e5af5b4c8640b5d97f573729e Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Fri, 12 Oct 2012 13:31:06 +0000 Subject: [PATCH] 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 --- .../commons/csv/perf/PerformanceTest.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java b/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java index 4ba0530b..943075eb 100644 --- a/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java +++ b/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java @@ -30,6 +30,7 @@ import java.io.Reader; import java.util.zip.GZIPInputStream; import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVRecord; import org.apache.commons.io.IOUtils; import org.junit.BeforeClass; import org.junit.Ignore; @@ -64,13 +65,18 @@ public class PerformanceTest { return new BufferedReader(new FileReader(BIG_FILE)); } - private long parse(final Reader in) throws IOException { + private long parse(final Reader in, boolean traverseColumns) throws IOException { final CSVFormat format = CSVFormat.DEFAULT.withIgnoreSurroundingSpaces(false); - long count = 0; - for (final Object record : format.parse(in)) { - count++; + long recordCount = 0; + for (final CSVRecord record : format.parse(in)) { + recordCount++; + if (traverseColumns) { + for (String value : record) { + // do nothing for now + } + } } - return count; + return recordCount; } private void println() { @@ -89,9 +95,9 @@ public class PerformanceTest { return count; } - public long testParseBigFile() throws Exception { + public long testParseBigFile(boolean traverseColumns) throws Exception { final long startMillis = System.currentTimeMillis(); - final long count = this.parse(this.getBufferedReader()); + final long count = this.parse(this.getBufferedReader(), traverseColumns); final long totalMillis = System.currentTimeMillis() - startMillis; this.println(String.format("File parsed in %,d milliseconds with Commons CSV: %,d lines.", totalMillis, count)); return totalMillis; @@ -101,7 +107,7 @@ public class PerformanceTest { public void testParseBigFileRepeat() throws Exception { long bestTime = Long.MAX_VALUE; for (int i = 0; i < this.max; i++) { - bestTime = Math.min(this.testParseBigFile(), bestTime); + bestTime = Math.min(this.testParseBigFile(false), bestTime); } this.println(String.format("Best time out of %,d is %,d milliseconds.", this.max, bestTime)); }