Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- static class A {
- public Integer a() { return 1; }
- }
- public static void main(String[] args) throws Exception {
- doRegular();
- doReflection2();
- doReflection();
- }
- public static void doRegular() throws Exception {
- A a = new A();
- long start = System.currentTimeMillis();
- for (int i=0; i<10000000; i++) {
- a.a();
- }
- System.out.println(System.currentTimeMillis() - start);
- }
- public static void doReflection() throws Exception {
- A a = new A();
- long start = System.currentTimeMillis();
- for (int i=0; i<10000000; i++) {
- A.class.getMethod("a").invoke(a);
- }
- System.out.println(System.currentTimeMillis() - start);
- }
- public static void doReflection2() throws Exception {
- A a = new A();
- java.lang.reflect.Method method = A.class.getMethod("a");
- long start = System.currentTimeMillis();
- for (int i=0; i<10000000; i++) {
- method.invoke(a);
- }
- System.out.println(System.currentTimeMillis() - start);
- }
- }
Add Comment
Please, Sign In to add comment