我想把现在的奔腾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();        
    }

}

解决方案 »

  1.   

    奔腾E6500 2.93GHz 
    画一次最快2604毫秒
      

  2.   

    64位CPU要想体现优势,得安装支持64位的操作系统,安装JDK x64版本,否则很大的可能反而不如在32位上的表现。
      

  3.   

    影响因素:
    1.x64版本的JRE
    2.代码是否针对多核优化
    3.System.currentTimeMillis()系统时间耗时不等于CPU耗时,要不intel的Parallel studio XE价值2000刀干嘛的,这样计算在关闭所有其他非系统关键程序时会更快的
    其实还有个因素,我不确定:
    java的VM一般在开机时会有后台,程序运行一次后,第二次运行加载明显加快,怀疑是内存中对象未完全释放,后台保留了加载时的对象以快速加载,如果是这样,怎么计算时间?
      

  4.   

    如上也能解释CPU计算能力相差不大的时候4.6秒和2.6秒的明显差距
      

  5.   

    p61 win7 最快2224 平均3000
      

  6.   


    同样E6500 2.93
    最快2000ms整 很奇怪到不了1999ms
      

  7.   

    跟64bit关系不大,大多数程序真的用64bit的环境,跑的比32bit的还慢。关系最大的主要是主频。不过,楼主为啥用awt来测试CPU速度?有啥特殊考虑么?打算连显卡一起捎带测试了?
      

  8.   

    [code=BatchFile]F:\temp>javac DrawSquare3.javaF:\temp>java DrawSquare3
    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
      

  9.   

    x64环境+x64jre会比x86jre快的,楼主可以google下,只是快的不多就是
    x64效果最明显我见过的是matlab,运行需3秒程序能比写x86快接近一秒
      

  10.   

    Intel(R) Core(TM) i7 CPU       Q 720  @ 1.60GHz
    64位ubuntu2063
    1171
    982
    928
    935
    955
    891
    1227
    1519
    1498
    1485
    1227
    994
    1003
    1163
    1177
      

  11.   

    Inter(R) core(tm) i5 cpu [email protected] 3.33ghz
    4.00gb(1.87gb可用)
    32位win7
    920
    875
    873
    891
    889
    890
    827
    812
    827
    952
    890
    890
    842
    875
    905
      

  12.   

    没人把 JDK 7 升级到最新版本么?
      

  13.   

    1158
    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  公司电脑。