KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > cglib > Main


1 package net.sf.cglib;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 import net.sf.cglib.reflect.FastClass;
6 import net.sf.cglib.reflect.FastMethod;
7
8 public class Main {
9
10     /**
11      * @param args
12      */

13     public static void main(String JavaDoc[] args) throws Exception JavaDoc{
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 JavaDoc{
39         
40         Main incer = new Main();
41         Method JavaDoc method = null;
42         Object JavaDoc[] args = new Object JavaDoc[]{new Integer JavaDoc(0),new Integer JavaDoc(0),new Integer JavaDoc(0)};
43        
44           method = Main.class.getMethod("test", new Class JavaDoc[]{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 JavaDoc {
57         Main incer = new Main();
58         FastMethod method = null;
59         Object JavaDoc[] args = new Object JavaDoc[]{new Integer JavaDoc(0),new Integer JavaDoc(0),new Integer JavaDoc(0)};
60        
61           FastClass c = FastClass.create(Main.class);
62           method = c.getMethod("test", new Class JavaDoc[]{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