1 package net.sf.cglib; 2 3 import java.lang.reflect.Method ; 4 5 import net.sf.cglib.reflect.FastClass; 6 import net.sf.cglib.reflect.FastMethod; 7 8 public class Main { 9 10 13 public static void main(String [] args) throws Exception { 14 15 int cnt = 100000; 16 long time; 17 18 19 System.getProperties().save(System.out,""); 20 21 System.out.print("CGLIB "); 22 time = fastReflectCall(cnt); 23 System.out.println( time); 24 25 System.out.print("REFLECTION "); 26 time = reflectCall(cnt); 27 System.out.println( time ); 28 29 30 31 } 32 33 34 public static int test(int i,int ii, int iiii){ 35 return 0; 36 } 37 38 public static long reflectCall(int its) throws Exception { 39 40 Main incer = new Main(); 41 Method method = null; 42 Object [] args = new Object []{new Integer (0),new Integer (0),new Integer (0)}; 43 44 method = Main.class.getMethod("test", new Class []{int.class,int.class,int.class}); 45 long time = System.currentTimeMillis(); 46 for (int i = 0; i < its; ++i) { 47 method.invoke(incer, args); 48 } 49 return System.currentTimeMillis() - time; 50 51 } 52 53 54 55 56 public static long fastReflectCall(int its)throws Exception { 57 Main incer = new Main(); 58 FastMethod method = null; 59 Object [] args = new Object []{new Integer (0),new Integer (0),new Integer (0)}; 60 61 FastClass c = FastClass.create(Main.class); 62 method = c.getMethod("test", new Class []{int.class,int.class,int.class}); 63 long time = System.currentTimeMillis(); 64 for (int i = 0; i < its; ++i) { 65 method.invoke(incer, args); 66 } 67 return System.currentTimeMillis() - time; 68 } 69 70 } 71 72 73 74 | Popular Tags |