测试代码: 有疑惑的可以post代码我来运行
import java.util.Random;import junit.framework.TestCase;/*
 * Created on 2004-11-24
 * @author steeven
 * <pre>windows amd64
testInt: 610
testLong: 859
testFloat: 1406
testDouble: 953
testConstruct: 2985
testException: 3547
testRandom: 7328
</pre> 
<pre>linux fodora 3 amd64
testInt: 8
testLong: 7
testFloat: 7
testDouble: 7
testConstruct: 3420
testException: 2867
testRandom: 1916
</pre>
 */
public class Performance extends TestCase{ private static long start;
int count = (int)1e8;
int count1 = (int)1e6; public static void main(String[] args) {
} public void setUp() {
start = System.currentTimeMillis();
} public void cleanUp() {
StackTraceElement[] traces = Thread.currentThread().getStackTrace();
String item = traces[3].getMethodName();
start = System.currentTimeMillis() - start;
System.out.println(item+":\t" + start);
} public void testInt() {
int a = 12345;
for (int i = 0; i < count; i++) {
a = a * i + a *a;
}
cleanUp();
}
public void testLong() {

long a = 12345L;
for (int i = 0; i < count; i++) {
a = a * i + a *a;
}
cleanUp();
}
public void testFloat() {

float a = 12345.6789F;
for (int i = 0; i < count; i++) {
a = a * i + a *a;
}
cleanUp();
}
public void testDouble() {

double a = 12345.6789D;
for (int i = 0; i < count; i++) {
a = a * i + a *a;
}
cleanUp();
}
public void testConstruct() {

Performance a = null;
for (int i = 0; i < count; i++) {
a = new Performance();
}
cleanUp();
}
public void testException() {


for (int i = 0; i < count1; i++) {
try {
throw new Exception("test");
} catch (Exception e) {
}
}
cleanUp();
}
public void testRandom() {

Random a = new Random(System.currentTimeMillis());
for (int i = 0; i < count; i++) {
a.nextLong();
}
cleanUp();
}}

解决方案 »

  1.   

    测试代码就在上面.我也搞不懂,如果7ms执行一亿次循环, 那1sec应该执行140亿的循环. 
    而且,每次循环里面要i++, 判断i<count, 两次乘法, 一次加法, 一次附值. 
    加起来大概1000亿次cpu运算了. cpu应该是100G了!实际上只是3G, 64位运算按照预想只能提高一倍性能而已.请高手指点迷津.
      

  2.   

    3G是指的CPU的时钟频率,而我们通常说的运算速度是指每秒做的浮点运算次数...
      

  3.   

    linux下的代码可能被优化过了。
      

  4.   

    不知道java 和 数据库的连接统计计算与.net 和 数据库的连接计算时间上会有多大不同.
      

  5.   


    32位windows没有对64位计算的支持。但linux有对64位计算的支持。
    你改用64位Windows试试