Am 22. März 2012 17:28 schrieb  <s...@apache.org>:
> Author: sebb
> Date: Thu Mar 22 16:28:47 2012
> New Revision: 1303878
>
> URL: http://svn.apache.org/viewvc?rev=1303878&view=rev
> Log:
> Allow testing of dynamically loaded CSVLexers
>

I'm not sure if I understand where you are going with this. Don't you
think it's a bit over engineered to put reflection into the
performance test? Are you doing that, because you want to test new
CSVLexer implementations using the CSVLexer1? The performance test
starts to get complex. Maybe you should explain to the ML, what you
are planning?

Benedikt

> Modified:
>    
> commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java
>
> Modified: 
> commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java
> URL: 
> http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java?rev=1303878&r1=1303877&r2=1303878&view=diff
> ==============================================================================
> --- 
> commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java
>  (original)
> +++ 
> commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java
>  Thu Mar 22 16:28:47 2012
> @@ -20,6 +20,8 @@ package org.apache.commons.csv;
>  import java.io.BufferedReader;
>  import java.io.FileReader;
>  import java.io.IOException;
> +import java.lang.reflect.Constructor;
> +import java.lang.reflect.InvocationTargetException;
>
>  /**
>  * Basic test harness.
> @@ -86,10 +88,14 @@ public class PerformanceTest {
>                 testCSVLexer(false, test);
>             } else if ("lexnew".equals(test)) {
>                 testCSVLexer(true, test);
> +            } else if (test.startsWith("CSVLexer")) {
> +                testCSVLexer(false, test);
>             } else if ("extb".equals(test)) {
>                 testExtendedBuffer(false);
>             } else if ("exts".equals(test)) {
>                 testExtendedBuffer(true);
> +            } else {
> +                System.out.println("Invalid test name: "+test);
>             }
>         }
>     }
> @@ -198,11 +204,26 @@ public class PerformanceTest {
>        show();
>    }
>
> +
> +   private static Constructor<Lexer> getLexerCtor(String clazz) throws 
> Exception {
> +       @SuppressWarnings("unchecked")
> +       Class<Lexer> lexer = (Class<Lexer>) 
> Class.forName("org.apache.commons.csv."+clazz);
> +       Constructor<Lexer> ctor = lexer.getConstructor(new 
> Class<?>[]{CSVFormat.class, ExtendedBufferedReader.class});
> +       return ctor;
> +   }
> +
>    private static void testCSVLexer(final boolean newToken, String test) 
> throws Exception {
>        Token token = new Token();
> +       String dynamic = "";
>        for (int i = 0; i < max; i++) {
> -           final BufferedReader reader = getReader();
> -           Lexer lexer = new CSVLexer(format, new 
> ExtendedBufferedReader(reader));
> +           final ExtendedBufferedReader input = new 
> ExtendedBufferedReader(getReader());
> +           Lexer lexer = null;
> +           if (test.startsWith("CSVLexer")) {
> +               dynamic="!";
> +               lexer = getLexerCtor(test).newInstance(new Object[]{format, 
> input});
> +           } else {
> +               lexer = new CSVLexer(format, input);
> +           }
>            int count = 0;
>            int fields = 0;
>            long t0 = System.currentTimeMillis();
> @@ -229,8 +250,8 @@ public class PerformanceTest {
>
>            } while (!token.type.equals(Token.Type.EOF));
>            Stats s = new Stats(count, fields);
> -           reader.close();
> -           show(test, s, t0);
> +           input.close();
> +           show(lexer.getClass().getSimpleName()+dynamic+" "+(newToken ? 
> "new" : "reset"), s, t0);
>        }
>        show();
>    }
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to