粉碎java [英] crushing java

查看:56
本文介绍了粉碎java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里有一个小小的测试程序。

它是如此简单,它应该提供类似的结果。

它也是如此简单以至于人们可能会说这对于更宽松的人来说是不公平的(b>为什么Java人总是那样争论?)...


无论如何都要看看测试命令行:

javac SimplePerf.java&& java SimplePerf 10000000

csc / nologo SimplePerf.cs&& SimplePerf 10000000

here a little test program.
it''s so simple taht it should deliver simmilar result.
it''s also so simple that people that might says it''s unfair to the looser
(why Java people are always arguing like that ?)...

anyway see for yourself the test command lines:
javac SimplePerf.java && java SimplePerf 10000000
csc /nologo SimplePerf.cs && SimplePerf 10000000


推荐答案

Lloyd Dupont< ld@NewsAccount.galador.net>写道:
Lloyd Dupont <ld@NewsAccount.galador.net> wrote:
这里有一个小小的测试程序。
它是如此简单,它应该提供相似的结果。
它也是如此简单,人们可能会说它这对于更宽松的人来说是不公平的(为什么Java人总是那样争论?)...
here a little test program.
it''s so simple taht it should deliver simmilar result.
it''s also so simple that people that might says it''s unfair to the looser
(why Java people are always arguing like that ?)...




恭喜你 - 你已经证明了用于Java的JIT编译器并不是
可以删除对Math.cos的调用。


现在,您认为这是多么适用?你的程序是否充满了

调用trig方法,这些方法实际上并不相关?

实际上,如果你修复了程序,它*会*使用该值, .NET仍然很容易获胜 - 但是你认为这甚至可以在目前的形式中稍微有点实用,这有点让人感兴趣。


(我使用JDK1.4.2运行;尝试使用IBM

JDK会很有趣,因为传统上浮点数更好。)

>
-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复该群组,请不要给我发邮件。 />



Congratulations - you''ve shown that the JIT compiler for Java doesn''t
spot that the call to Math.cos can be removed.

Now, how applicable do you believe that is? Are your programs full of
calls to trig methods which aren''t actually relevant?
In fact, if you fix the program so it *does* use the value, .NET still
wins easily - but the fact that you thought this was even slightly
useful in its current form is somewhat interesting.

(I was running with JDK1.4.2; it would be interesting to try the IBM
JDK as that''s traditionally been better for floating point stuff.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


正如约翰所说,有很多事情可以解释这一点。而C#和Java是完全不同的,比较两者很难,在很多情况下毫无意义(苹果和橘子)。


奇怪的是,当试图强迫Math.Cos工作时C#我添加了一个double [10000000]数组并将每个值存储在那里。这将C#的执行时间从我的系统上的0-16毫秒增加到大约1.4秒。但是,java无法创建该大小的双精度数组。 ??? OutOfMemoryError


看看非Windows系统上的某个人是否可以运行代码(或任何使用Windows的人)会很有趣。


我的修改代码是


C#


public static void Main(string [] args)

{

int N = int.Parse(" 10000000");

double [] d = new double [N];

long t0 = Environment.TickCount ;

for(int i = 0; i< N; i ++)

{

d [i] = Math.Cos(i);

}

Console.WriteLine(Environment.TickCount -t0);

}


Java


public static void main(String [] args)

{

int N = Integer.parseInt(" 10000000" );

double [] d = new double [N];

long t0 = System.currentTimeMillis();

for(int i = 0; i< N; i ++)

{

d [i] = Math.cos(i);

}

System.out.println(System.currentTimeMillis() - t0);

}


-

快乐的编码!

Morten Wennevik [C#MVP]
As John said, there are a number of things that might explain this. And C# and Java is sufficiently different that comparing the two is difficult and in many cases pointless (Apples and Oranges).

Strange thing though, when trying to force Math.Cos do work in C# I added a double[10000000] array and stored each value in there. This increased the execution time for C# from 0-16 ms on my system to about 1.4 seconds. However, java was incapable of creating a double array of that size. ??? OutOfMemoryError

It would be interesting to see if someone on non Windows systems could run the code (or anyone using Windows).

My modified code is

C#

public static void Main(string[] args)
{
int N = int.Parse("10000000");
double[] d = new double[N];
long t0 = Environment.TickCount;
for(int i=0 ; i< N; i++)
{
d[i] = Math.Cos(i);
}
Console.WriteLine(Environment.TickCount-t0);
}

Java

public static void main(String[] args)
{
int N = Integer.parseInt("10000000");
double[] d = new double[N];
long t0 = System.currentTimeMillis();
for(int i=0; i< N; i++)
{
d[i] = Math.cos(i);
}
System.out.println(System.currentTimeMillis()-t0);
}

--
Happy coding!
Morten Wennevik [C# MVP]


Morten Wennevik< Mo * ***********@hotmail.com>写道:
Morten Wennevik <Mo************@hotmail.com> wrote:
正如约翰所说,有许多事情可以解释这一点。
和C#和Java完全不同,比较两者是困难的,在很多情况下毫无意义(苹果和橘子)。

奇怪的是,当试图强迫Math.Cos在C#中工作时我添加了一个双[10000000]数组并将每个值存储在那里。这使得C#的执行时间从我的系统上的0-16毫秒增加到大约1.4秒。但是,java无法创建该大小的双重数组。 ??? OutOfMemoryError
As John said, there are a number of things that might explain this.
And C# and Java is sufficiently different that comparing the two is
difficult and in many cases pointless (Apples and Oranges).

Strange thing though, when trying to force Math.Cos do work in C# I
added a double[10000000] array and stored each value in there. This
increased the execution time for C# from 0-16 ms on my system to
about 1.4 seconds. However, java was incapable of creating a double
array of that size. ??? OutOfMemoryError




这不是Java无法创建数组 - 它是

最大堆大小设置默认为64Mb。用-Xmx128M运行它到

给它128MB代替。


然而,不是存储所有的双打,另一种方法是保持一个

单个双变量并将Math.Cos的结果添加到每个
迭代中。它正在测试浮点数的增加,

当然。


-

Jon Skeet - < sk***@pobox.com>
http://www.pobox。 com / ~siget

如果回复小组,请不要给我发邮件



It''s not an inability of Java to create the array - it''s that the
maximum heap size is set to 64Mb by default. Run it with -Xmx128M to
give it 128MB instead.

However, rather than storing all the doubles, another way is to keep a
single double variable and add the result of Math.Cos to that on each
iteration. It''s then testing floating point addition as well, of
course.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于粉碎java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆