Java反射获取实例的速度对比-创新互联
本篇文章给大家分享的是有关Java反射获取实例的速度对比,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

public static void main(String[] args) {
try {
int MAX = 100000;
for (int count = 0; count < 50; count++) {
System.out.println("====第" + count+"次");
long s1 = System.currentTimeMillis();
for (int i = 0; i < MAX; i++) {
Person o = (Person)Class.forName("com.qingtai.domin.Person").newInstance();
}
long e1 = System.currentTimeMillis();
System.out.println("1_duration:" + (e1 - s1));
long s2 = System.currentTimeMillis();
Class clazz = Class.forName("com.qingtai.domin.Person");
for (int i = 0; i < MAX; i++) {
Person person = (Person) clazz.newInstance();
}
long e2 = System.currentTimeMillis();
System.out.println("2_duration:" + (e2 - s2));
}
} catch (Exception e) {
e.printStackTrace();
}
} 网站栏目:Java反射获取实例的速度对比-创新互联
网页地址:http://www.scyingshan.cn/article/deogeh.html


咨询
建站咨询
