55 * The ASF licenses this file to You under the Apache License, Version 2.0
66 * (the "License"); you may not use this file except in compliance with
77 * the License. You may obtain a copy of the License at
8- *
8+ *
99 * http://www.apache.org/licenses/LICENSE-2.0
10- *
10+ *
1111 * Unless required by applicable law or agreed to in writing, software
1212 * distributed under the License is distributed on an "AS IS" BASIS,
1313 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2323
2424/**
2525 * Basic test harness.
26- *
26+ *
2727 * Requires test file to be downloaded separately.
28- *
28+ *
2929 */
3030@ SuppressWarnings ("boxing" )
3131public class PerformanceTest {
3232
3333 private static final String [] PROPS = {
34- "java.version" , // Java Runtime Environment version
35- "java.vendor" , // Java Runtime Environment vendor
36- // "java.vm.specification.version", // Java Virtual Machine specification version
37- // "java.vm.specification.vendor", // Java Virtual Machine specification vendor
38- // "java.vm.specification.name", // Java Virtual Machine specification name
39- "java.vm.version" , // Java Virtual Machine implementation version
40- // "java.vm.vendor", // Java Virtual Machine implementation vendor
41- "java.vm.name" , // Java Virtual Machine implementation name
42- // "java.specification.version", // Java Runtime Environment specification version
43- // "java.specification.vendor", // Java Runtime Environment specification vendor
44- // "java.specification.name", // Java Runtime Environment specification name
45-
46- "os.name" , // Operating system name
47- "os.arch" , // Operating system architecture
48- "os.version" , // Operating system version
49-
34+ "java.version" , // Java Runtime Environment version
35+ "java.vendor" , // Java Runtime Environment vendor
36+ // "java.vm.specification.version", // Java Virtual Machine specification version
37+ // "java.vm.specification.vendor", // Java Virtual Machine specification vendor
38+ // "java.vm.specification.name", // Java Virtual Machine specification name
39+ "java.vm.version" , // Java Virtual Machine implementation version
40+ // "java.vm.vendor", // Java Virtual Machine implementation vendor
41+ "java.vm.name" , // Java Virtual Machine implementation name
42+ // "java.specification.version", // Java Runtime Environment specification version
43+ // "java.specification.vendor", // Java Runtime Environment specification vendor
44+ // "java.specification.name", // Java Runtime Environment specification name
45+
46+ "os.name" , // Operating system name
47+ "os.arch" , // Operating system architecture
48+ "os.version" , // Operating system version
49+
5050 };
51-
51+
5252 private static int max = 10 ;
5353
5454 private static int num = 0 ; // number of elapsed times recorded
5555 private static long [] elapsedTimes = new long [max ];
56-
56+
5757 private static final CSVFormat format = CSVFormat .EXCEL ;
5858
5959 public static void main (String [] args ) throws Exception {
@@ -68,24 +68,28 @@ public static void main(String [] args) throws Exception {
6868 tests [i -1 ]=args [i ];
6969 }
7070 } else {
71- tests =new String []{"file" , "split" , "extb" , "exts" , "csv" };
71+ tests =new String []{"file" , "split" , "extb" , "exts" , "csv" , "lexreset" , "lexnew" };
7272 }
7373 for (String p : PROPS ) {
74- System .out .println (p +"=" +System .getProperty (p ));
74+ System .out .println (p +"=" +System .getProperty (p ));
7575 }
7676 System .out .println ("Max count: " +max +"\n " );
7777
7878 for (String test : tests ) {
7979 if ("file" .equals (test )) {
80- testReadBigFile (false );
80+ testReadBigFile (false );
8181 } else if ("split" .equals (test )) {
82- testReadBigFile (true );
82+ testReadBigFile (true );
8383 } else if ("csv" .equals (test )) {
84- testParseCommonsCSV ();
84+ testParseCommonsCSV ();
85+ } else if ("lexreset" .equals (test )) {
86+ testCSVLexer (false , test );
87+ } else if ("lexnew" .equals (test )) {
88+ testCSVLexer (true , test );
8589 } else if ("extb" .equals (test )) {
86- testExtendedBuffer (false );
90+ testExtendedBuffer (false );
8791 } else if ("exts" .equals (test )) {
88- testExtendedBuffer (true );
92+ testExtendedBuffer (true );
8993 }
9094 }
9195 }
@@ -173,7 +177,7 @@ private static void testExtendedBuffer(boolean makeString) throws Exception {
173177 } else if (read == '\n' ) {
174178 lines ++;
175179 }
176- }
180+ }
177181 }
178182 fields += lines ; // EOL is a delimiter too
179183 in .close ();
@@ -194,6 +198,43 @@ private static void testParseCommonsCSV() throws Exception {
194198 show ();
195199 }
196200
201+ private static void testCSVLexer (final boolean newToken , String test ) throws Exception {
202+ Token token = new Token ();
203+ for (int i = 0 ; i < max ; i ++) {
204+ final BufferedReader reader = getReader ();
205+ Lexer lexer = new CSVLexer (format , new ExtendedBufferedReader (reader ));
206+ int count = 0 ;
207+ int fields = 0 ;
208+ long t0 = System .currentTimeMillis ();
209+ do {
210+ if (newToken ) {
211+ token = new Token ();
212+ } else {
213+ token .reset ();
214+ }
215+ lexer .nextToken (token );
216+ switch (token .type ) {
217+ case EOF :
218+ break ;
219+ case EORECORD :
220+ fields ++;
221+ count ++;
222+ break ;
223+ case INVALID :
224+ throw new IOException ("invalid parse sequence" );
225+ case TOKEN :
226+ fields ++;
227+ break ;
228+ }
229+
230+ } while (!token .type .equals (Token .Type .EOF ));
231+ Stats s = new Stats (count , fields );
232+ reader .close ();
233+ show (test , s , t0 );
234+ }
235+ show ();
236+ }
237+
197238 private static Stats iterate (Iterable <CSVRecord > it ) {
198239 int count = 0 ;
199240 int fields = 0 ;
0 commit comments