You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Benedikt Ritter <be...@googlemail.com> on 2012/03/23 08:31:56 UTC

Re: svn commit: r1303878 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java

Am 22. März 2012 17:28 schrieb  <se...@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-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1303878 - /commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/PerformanceTest.java

Posted by sebb <se...@gmail.com>.
On 23 March 2012 07:31, Benedikt Ritter <be...@googlemail.com> wrote:
> Am 22. März 2012 17:28 schrieb  <se...@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?

No, see below.

> Are you doing that, because you want to test new
> CSVLexer implementations using the CSVLexer1?

To test new subclasses of the abstract Lexer.

> The performance test starts to get complex.

It actually gets more complex to keep adding/subtracting new tests.

I originally did that at first locally, and it was a pain.

> Maybe you should explain to the ML, what you are planning?

This makes it much easier to test new implementations.

Just create the new Lexer implementation, and then run the test.
No need to update the test harness.

And when the test is completed, the implementation can be deleted
without having to fix the performance test again.

Note: I don't plan to extend the reflective invocation further.

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