[jboss-user] [JBoss Seam] - Re: Further extending an EntityHome
mustaghattack
do-not-reply at jboss.com
Tue Sep 25 05:03:39 EDT 2007
Hi, about the EntityHome class I think it would be better to just pass the entity class as a parameter for the constructor, or at least to have a parameterized constructor.
I've done a quick performance test to see the reflection overhead :
with a Sun 1.6 JVM it's > 30.
| package test.java;
|
| import java.lang.reflect.ParameterizedType;
| import java.lang.reflect.Type;
|
| public class GuessParameterizePerformanceTest {
| public static class GuessParam< E > {
| private Class< E > entityClass;
|
| public GuessParam() {
| getEntityClass();
| }
|
| public Class<E> getEntityClass()
| {
| if (entityClass==null)
| {
| Type type = getClass().getGenericSuperclass();
| if (type instanceof ParameterizedType)
| {
| ParameterizedType paramType = (ParameterizedType) type;
| entityClass = (Class<E>) paramType.getActualTypeArguments()[0];
| }
| else
| {
| throw new IllegalArgumentException("Could not guess entity class by reflection");
| }
| }
| return entityClass;
| }
| }
|
| public static class DontGuessParam< E > {
| private Class< E > entityClass;
|
| public DontGuessParam( Class< E > cls ) {
| this.entityClass = cls;
| getEntityClass();
| }
|
| public Class< E > getEntityClass() {
| return entityClass;
| }
| }
|
| public static class GuessParamChild extends GuessParam< String > {
| }
|
| public static class DontGuessParamChild extends DontGuessParam< String > {
| public DontGuessParamChild() {
| super( String.class );
| }
| }
|
| public static void main(String[] args) {
| float avgGuess = 0, avgDontGuess = 0;
| float nbLoop = 5, nbInstanciation = 1000000;
| long time;
|
| for( long i = 0; i < nbLoop; i ++ ) {
| time = System.currentTimeMillis();
| for( long j = 0; j < nbInstanciation; j ++ ) {
| GuessParamChild guess = new GuessParamChild();
| }
| avgGuess += System.currentTimeMillis() - time;
|
| time = System.currentTimeMillis();
| for( long j = 0; j < nbInstanciation; j ++ ) {
| DontGuessParamChild dontGuess = new DontGuessParamChild();
| }
| avgDontGuess += System.currentTimeMillis() - time;
| }
|
| System.out.println("avgGuess = " + (avgGuess / nbLoop));
| System.out.println("avgDontGuess = " + (avgDontGuess / nbLoop));
| System.out.println( "Guess overhead : " + ( avgGuess - avgDontGuess ) / avgDontGuess );
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4088302#4088302
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4088302
More information about the jboss-user
mailing list