@@ -57,14 +57,37 @@ public class PerformanceTest {
5757 private static final CSVFormat format = CSVFormat .DEFAULT .withSurroundingSpacesIgnored (false );
5858
5959 public static void main (String [] args ) throws Exception {
60+ final int argc = args .length ;
61+ String tests [];
62+ if (argc > 0 ) {
63+ max =Integer .parseInt (args [0 ]);
64+ }
65+ if (argc > 1 ) {
66+ tests = new String [argc -1 ];
67+ for (int i = 1 ; i < argc ; i ++) {
68+ tests [i -1 ]=args [i ];
69+ }
70+ } else {
71+ tests =new String []{"file" , "split" , "extb" , "exts" , "csv" };
72+ }
6073 for (String p : PROPS ) {
6174 System .out .println (p +"=" +System .getProperty (p ));
6275 }
6376 System .out .println ("Max count: " +max +"\n " );
6477
65- testReadBigFile (false );
66- testReadBigFile (true );
67- testParseCommonsCSV ();
78+ for (String test : tests ) {
79+ if ("file" .equals (test )) {
80+ testReadBigFile (false );
81+ } else if ("split" .equals (test )) {
82+ testReadBigFile (true );
83+ } else if ("csv" .equals (test )) {
84+ testParseCommonsCSV ();
85+ } else if ("extb" .equals (test )) {
86+ testExtendedBuffer (false );
87+ } else if ("exts" .equals (test )) {
88+ testExtendedBuffer (true );
89+ }
90+ }
6891 }
6992
7093 private static BufferedReader getReader () throws IOException {
@@ -122,6 +145,41 @@ private static Stats readAll(BufferedReader in, boolean split) throws IOExceptio
122145 return new Stats (count , fields );
123146 }
124147
148+ private static void testExtendedBuffer (boolean makeString ) throws Exception {
149+ for (int i = 0 ; i < max ; i ++) {
150+ ExtendedBufferedReader in = new ExtendedBufferedReader (getReader ());
151+ long t0 = System .currentTimeMillis ();
152+ int read ;
153+ int fields = 0 ;
154+ int lines = 0 ;
155+ if (makeString ) {
156+ StringBuilder sb = new StringBuilder ();
157+ while ((read =in .read ()) != -1 ) {
158+ sb .append ((char )read );
159+ if (read == ',' ) { // count delimiters
160+ fields ++;
161+ } else if (read == '\n' ) {
162+ lines ++;
163+ sb .toString ();
164+ sb = new StringBuilder ();
165+ }
166+ }
167+ } else {
168+ while ((read =in .read ()) != -1 ) {
169+ if (read == ',' ) { // count delimiters
170+ fields ++;
171+ } else if (read == '\n' ) {
172+ lines ++;
173+ }
174+ }
175+ }
176+ fields += lines ; // EOL is a delimiter too
177+ in .close ();
178+ show ("Extended" +(makeString ?" toString" :"" ), new Stats (lines , fields ), t0 );
179+ }
180+ show ();
181+ }
182+
125183 private static void testParseCommonsCSV () throws Exception {
126184 for (int i = 0 ; i < max ; i ++) {
127185 final BufferedReader reader = getReader ();
0 commit comments