我想把现在的奔腾4 2.8GHZ换成一个64位的CPU,但不知道64位CPU会快多少,所以写了一个测试程序,我的计算机运行这个程序花了4.6秒。我想各位也用我的测试程序测试一下你的计算机的运行速度,然后我根据你们的运行时间和我的对比,我就可以知道新的CPU能够快多少了。谢谢。import java.util.*;
import java.applet.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.Graphics;
import java.awt.Color;public class DrawSquare3 extends JFrame {
Frame f1;
Canvas cvs;
Graphics gf, gh;
Image ig;
public DrawSquare3() {
this.setSize(800,800);
this.setVisible(true);
cvs = new Canvas();
cvs.setSize(this.getSize().width, this.getSize().height);
this.getContentPane().add(cvs,BorderLayout.CENTER);
this.pack();
cvs.setBackground(Color.BLACK);
gf = cvs.getGraphics();
gf.setColor(Color.yellow);ig = createImage(this.getSize().width, this.getSize().height);
gh = ig.getGraphics();
while (true) {
int i = 1;
long s = System.currentTimeMillis();
while (i < 600) {
gh.setColor(Color.black);
gh.fillRect(0,0,this.getSize().width, this.getSize().height);
gh.setColor(Color.BLUE);
gh.fillRect(0,0,i,i);
cvs.getGraphics().drawImage(ig,0,0,null);
i = i + 1;
}
long e = System.currentTimeMillis();
System.out.println(""+(e-s));
}
}
public static void main(String[] args) {
JFrame dd= new DrawSquare3();
}
}
import java.applet.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.Graphics;
import java.awt.Color;public class DrawSquare3 extends JFrame {
Frame f1;
Canvas cvs;
Graphics gf, gh;
Image ig;
public DrawSquare3() {
this.setSize(800,800);
this.setVisible(true);
cvs = new Canvas();
cvs.setSize(this.getSize().width, this.getSize().height);
this.getContentPane().add(cvs,BorderLayout.CENTER);
this.pack();
cvs.setBackground(Color.BLACK);
gf = cvs.getGraphics();
gf.setColor(Color.yellow);ig = createImage(this.getSize().width, this.getSize().height);
gh = ig.getGraphics();
while (true) {
int i = 1;
long s = System.currentTimeMillis();
while (i < 600) {
gh.setColor(Color.black);
gh.fillRect(0,0,this.getSize().width, this.getSize().height);
gh.setColor(Color.BLUE);
gh.fillRect(0,0,i,i);
cvs.getGraphics().drawImage(ig,0,0,null);
i = i + 1;
}
long e = System.currentTimeMillis();
System.out.println(""+(e-s));
}
}
public static void main(String[] args) {
JFrame dd= new DrawSquare3();
}
}
画一次最快2604毫秒
1.x64版本的JRE
2.代码是否针对多核优化
3.System.currentTimeMillis()系统时间耗时不等于CPU耗时,要不intel的Parallel studio XE价值2000刀干嘛的,这样计算在关闭所有其他非系统关键程序时会更快的
其实还有个因素,我不确定:
java的VM一般在开机时会有后台,程序运行一次后,第二次运行加载明显加快,怀疑是内存中对象未完全释放,后台保留了加载时的对象以快速加载,如果是这样,怎么计算时间?
同样E6500 2.93
最快2000ms整 很奇怪到不了1999ms
2509
2299
2248
2105
2035
2091
2128
2050
2107
2125
2204
2156
2248
2108[/code] OS: 32 位 Windows 7 Ultimate Service Pack 1
CPU: Intel Core Duo [email protected]
RAM: 4.00 GB(3.00 GB 可用)
JDK: 1.7.0_02
x64效果最明显我见过的是matlab,运行需3秒程序能比写x86快接近一秒
64位ubuntu2063
1171
982
928
935
955
891
1227
1519
1498
1485
1227
994
1003
1163
1177
4.00gb(1.87gb可用)
32位win7
920
875
873
891
889
890
827
812
827
952
890
890
842
875
905
1049
798
390
407
390
421
438
405
406
407
390
405
393
406
405
394
406
408
392
406
390
391
390
390
391
390
390
391
390
390
407
thinkPad e40 公司电脑。