1700452027
1700452028
try{
1700452029
1700452030
return super.clone();
1700452031
1700452032
}catch(CloneNotSupportedException e){
1700452033
1700452034
throw new Error();
1700452035
1700452036
}
1700452037
1700452038
}}
1700452039
1700452040
public static void main(String[]args){
1700452041
1700452042
//循环10万次
1700452043
1700452044
final int maxLoops=10*10000;
1700452045
1700452046
int loops=0;
1700452047
1700452048
//开始时间
1700452049
1700452050
long start=System.nanoTime();
1700452051
1700452052
//“母”对象
1700452053
1700452054
Apple apple=new Apple();
1700452055
1700452056
while(++loops<maxLoops){
1700452057
1700452058
apple.clone();
1700452059
1700452060
}
1700452061
1700452062
long mid=System.nanoTime();
1700452063
1700452064
System.out.println(“clone方法生成对象耗时:”+(mid-start)+“ns”);
1700452065
1700452066
//new生成对象
1700452067
1700452068
while(—loops>0){
1700452069
1700452070
new Apple();
1700452071
1700452072
}
1700452073
1700452074
long end=System.nanoTime();
1700452075
1700452076
System.out.println(“new生成对象耗时:”+(end-mid)+“ns”);
[
上一页 ]
[ :1.700452027e+09 ]
[
下一页 ]