commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1397559 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
Date Fri, 12 Oct 2012 13:31:06 GMT
Author: ggregory
Date: Fri Oct 12 13:31:06 2012
New Revision: 1397559

URL: http://svn.apache.org/viewvc?rev=1397559&view=rev
Log:
Allow performance test to traverse column values (optional).

Modified:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java?rev=1397559&r1=1397558&r2=1397559&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
(original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
Fri Oct 12 13:31:06 2012
@@ -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));
     }



Mime
View raw message