From b372050f7f238b14953e609d3ec28dc755fca685 Mon Sep 17 00:00:00 2001 From: "Gary D. Gregory" Date: Tue, 11 Sep 2012 18:18:14 +0000 Subject: [PATCH] Fix compilation issue. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1383504 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/csv/perf/PerformanceTest.java | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/test/java/org/apache/commons/csv/perf/PerformanceTest.java diff --git a/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java b/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java new file mode 100644 index 00000000..027c835b --- /dev/null +++ b/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java @@ -0,0 +1,81 @@ +package org.apache.commons.csv.perf; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + +import org.apache.commons.csv.CSVFormat; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Tests performance. + * + * Only enable for your own development. + */ +public class PerformanceTest { + + private final int max = 10; + + private BufferedReader getBufferedReader() throws IOException { + return new BufferedReader(new FileReader("src/test/resources/worldcitiespop.txt")); + } + + private long parse(Reader in) throws IOException { + CSVFormat format = CSVFormat.DEFAULT.withSurroundingSpacesIgnored(false); + long count = 0; + for (Object record : format.parse(in)) { + count++; + } + return count; + } + + private void println() { + System.out.println(); + } + + private void println(String s) { + System.out.println(s); + } + + private long readAll(BufferedReader in) throws IOException { + long count = 0; + while (in.readLine() != null) { + count++; + } + return count; + } + + @Test + @Ignore + public void testParseBigFile() throws Exception { + long t0 = System.currentTimeMillis(); + long count = this.parse(this.getBufferedReader()); + this.println("File parsed in " + (System.currentTimeMillis() - t0) + "ms with Commons CSV" + " " + count + + " lines"); + this.println(); + } + + @Test + @Ignore + public void testParseBigFileRepeat() throws Exception { + for (int i = 0; i < this.max; i++) { + this.testParseBigFile(); + } + this.println(); + } + + @Test + @Ignore + public void testReadBigFile() throws Exception { + for (int i = 0; i < this.max; i++) { + BufferedReader in = this.getBufferedReader(); + long t0 = System.currentTimeMillis(); + long count = this.readAll(in); + in.close(); + this.println("File read in " + (System.currentTimeMillis() - t0) + "ms" + " " + count + " lines"); + } + this.println(); + } +} \ No newline at end of file