一 代码
package com.cakin.javademo;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* @ClassName: Reflection
* @Description: 反射性能测试
* @Date: 2020/8/15
* @Author: cakin
*/
public class Reflection {
public static void main(String[] args) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
test1();
test2();
test3();
}
// 普通方式
public static void test1() {
Dog1 dog = new Dog1();
long startTime = System.currentTimeMillis();
for (int i = 0; i < 1000000000; i++) {
dog.getName();
}
long endTime = System.currentTimeMillis();
System.out.println("普通方式调用时间:" + (endTime - startTime));