Re: Tests Reflectasm

90 views
Skip to first unread message

Nate

unread,
Sep 12, 2013, 8:23:07 PM9/12/13
to Douglas Junior, reflecta...@googlegroups.com
Hi,

Please use the discussion group for support.

I haven't tested with Java 7, however, microbenchmarks are easy to get wrong and yours has many problems. Don't include ConstructorAccess.get or MethodAccess.get in the timing. Use the method index as described in the docs. Warm up the JVM. Run multiple tests and take the lowest time. Use System.nanoTime. You also need to run with the server VM outside of an IDE.

You might look into a Java framework for running microbenchmarks.

-Nate





On Fri, Sep 13, 2013 at 1:40 AM, Douglas Junior <nassi...@gmail.com> wrote:
Hello,

My name is Douglas, I and my team are looking for an API to replace relfection and improve performance.

Then find your project Refletasm, we downloaded the library and did some tests.

In one of our tests using the latest version of your library and java 7, we note that Reflection behaved much faster than Reflectasm.

I would like to know the best way to use your library and if we perform the tests correctly.

Thank you for your attention and congratulations for the initiative.

Hugs.



    int qtd = 1000000;

        long tempoInicio = System.currentTimeMillis(); 
        for (int i = 0; i < qtd; i++) {
            Pessoa someObject = new Pessoa();
            someObject.setNome("teste");
            someObject.setId(10);
            someObject.setAtivo(true);
        }
        System.out.println("Normal execution: "+(System.currentTimeMillis()-tempoInicio));
        tempoInicio = System.currentTimeMillis();
        for (int i = 0; i < qtd; i++) {
            ConstructorAccess<Pessoa> cAccess = ConstructorAccess
                    .get(Pessoa.class);
            Pessoa someObject = cAccess.newInstance();
            MethodAccess mAccess = MethodAccess.get(Pessoa.class);
            mAccess.invoke(someObject, "setNome", "Awesome McLovin");
            mAccess.invoke(someObject, "setId", 1);
            mAccess.invoke(someObject, "setAtivo", true);
        }
        System.out.println("Reflectasm: "+(System.currentTimeMillis()-tempoInicio));
        tempoInicio = System.currentTimeMillis();
        for (int i = 0; i < qtd; i++) {
            Class c = Class.forName("br.com.testereflectasm.Pessoa");
            Pessoa a = (Pessoa) c.newInstance();
            a.getClass().getMethod("setNome", String.class).invoke(a,"teste");
            a.getClass().getMethod("setId", Integer.class).invoke(a,1);
            a.getClass().getMethod("setAtivo", Boolean.class).invoke(a,true);
        }
        System.out.println("Reflection: "+(System.currentTimeMillis()-tempoInicio));
        tempoInicio = System.currentTimeMillis();
    }

Result:

Normal execution: 32 ms
Reflectasm: 16341 ms
Reflection: 8089 ms



Att
Douglas N Roma Jr
Analista de Sistemas - A.J. Rorato & Cia. LTDA
Tecnologia em Sistemas para Internet - UTFPR



Nate

unread,
Sep 12, 2013, 10:21:22 PM9/12/13
to Douglas Junior, reflecta...@googlegroups.com
Hi Douglas,

Great! :)

Unfortunately you'll find the ASM bytecode generation can't work on Android, which is Dalvik, not real Java.

-Nate




On Fri, Sep 13, 2013 at 2:55 AM, Douglas Junior <nassi...@gmail.com> wrote:
Thank you for the reply.

Really, removing the creation of these objects out of the loop performance improved greatly.

Normal call: 24
Reflectasm: 299
Reflection: 4301
Reflectutils: 3873


We are developing an ORM persistence for Java and Android,
and the question is that in Android are having a considerable loss of performance fault of Reflection.


We will study more deeply the Reflectasm.

Hugs.


Att
Douglas N Roma Jr
Analista de Sistemas - A.J. Rorato & Cia. LTDA
Tecnologia em Sistemas para Internet - UTFPR




2013/9/12 Nate <nathan...@gmail.com>
Reply all
Reply to author
Forward
0 new messages