易截截图软件、单文件、免安装、纯绿色、仅160KB

Java中利用final关键字inline编译优化真的有效吗?

  为寻求java代码的性能优化,从网上搜到利用final关键字进行编译时inline优化的方法,但是真的有效吗?实际测试中发现未必,甚至性能影响巨大,最终放弃了使用final优化的想法。
  测试环境:Windows XP SP2,JDK 1.6.0_15-b03,Eclipse 3.5 SR1。
package test;
public class Test {
public static void main(String[] args) {
int loop = 5000000;//测试500万循环
long start;
String num = "0";
//----第一遍----
start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
Class1 c1 = new Class1();
c1.setF1(num);
c1.getF1();
}
System.out.println((System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
Class2 c2 = new Class2();
c2.setF1(num);
c2.getF1();
}
System.out.println((System.currentTimeMillis() - start) + "ms");
//----第二遍----
start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
Class1 c1 = new Class1();
c1.setF1(num);
c1.getF1();
}
System.out.println((System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
Class2 c2 = new Class2();
c2.setF1(num);
c2.getF1();
}
System.out.println((System.currentTimeMillis() - start) + "ms");
//----第三遍----
start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
Class1 c1 = new Class1();
c1.setF1(num);
c1.getF1();
}
System.out.println((System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
for (int i = 0; i < loop; i++) {
Class2 c2 = new Class2();
c2.setF1(num);
c2.getF1();
}
System.out.println((System.currentTimeMillis() - start) + "ms");
}
}
class Class1 {
private String f1;
public String getF1() {
return f1;
}
public void setF1(String f1) {
this.f1 = f1;
}
}
final class Class2 {
private String f


相关文档:

java基础

JSP的9个内置对象是:out、request、response、page、pageContext、session、application、exception、config。要注意对象名的大小写
 
 
What results from attempting to compile and run the following code? public class Ternary{ public static void main(String args[]){ int a = 5; System.out.printl ......

初学JAVA之二

1、 串操作:使用字符串存贮一个英文句子“Java is an object oriented programming
 language”。显示该句子,并算出每个单词的字母数和平均字母数,并按单词升序排列输出(不用数组,只用串操作)
public class homework21 {
   public static void main(String[] args) {
  &nb ......

JAVA笔试题

第一:
1.String是最基本的数据类型么?
答:不是。基本的数据类型包括:byte,int,char,long,float,double,boolean和short.
java.lang.String类是final类型的,因此不可以继承这个类,不能修改这个类。
2.静态变量和实例变量的区别?
答:static i = 10 ;//常量  
      &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号