评测报告:.NET的性能仍然远远落后于Java

<script type="text/javascript"> </script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>

评测报告.NET性能仍然远远落后于Java

每个人都看过各种不同的benchmark,有证明.NETJava快的,也有证明Java.NET快的。在某些人的手里,benchmark是一面魔镜,透过它能看到想看的东西。所以,当这位名为Cameron的先生要开始在.NETJava之间做一个benchmark时,他认为自己就是在浪费时间,因为肯定会有人来证明.NETJava快。

顺便地,Cameron先生提出了10条“不要用于在.NETJava之间做选择”的理由,其中包括:

Ø         在某一组特定的benchmark中,某一个比另一个快一点;

Ø         MicrosoftSun(或者OracleIBM……)的报告说其中一个比另一个好得多;

Ø         你喜欢(或不喜欢)Bill Gates或者Scott McNeally(或者Larry Ellison);

Ø         你认为Microsoft或者Sun(或者IBM或者Oracle)很邪恶(或者很伟大);

Ø         你在TheServerSide.com或者GotDotNET.com(或者Microsoft.com)读了一篇“没有偏见”的文章;

实际上,这次benchmark源于CamerontRolf两人在TheServerSide.com网站的一次关于Web服务性能的争吵(http://www.theserverside.com/reviews/thread.jsp?thread_id=19226)。在这次的benchmark中,Cameron测试了下列版本:

.NET 1.0sp2:
  
  
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
   
   
for Microsoft (R) .NET Framework version 1.0.3705
   
   
Copyright (C) Microsoft Corporation 2001. All rights reserved.
  
  
.NET 1.1:
  
  
Microsoft (R) Visual C# .NET Compiler version 7.10.3052.4
   
   
for Microsoft (R) .NET Framework version 1.1.4322
   
   
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
  
  
Sun Hotspot Server JVM from JDK 1.3.1_04:
  
  
Java version "1.3.1_04"
   
   
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_04-b02)
   
   
Java HotSpot(TM) Server VM (build 1.3.1_04-b02, mixed mode)
  
  
Sun Hotspot Server JVM from JDK 1.4.0_02:
  
  
Java version "1.4.0_02"
   
   
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_02-b02)
   
   
Java HotSpot(TM) Server VM (build 1.4.0_02-b02, mixed mode)
  
  
Sun Hotspot Server JVM from JDK 1.4.1_02:
  
  
Java version "1.4.1_02"
   
   
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
   
   
Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
  
  

在代码方面,Cameron主要选择了大量ArrayList来进行测试。下列是他的测试代码:

C#

// C# Create 100,000 people in an ArrayList and access them

using System;

using System.Collections;

 

public class ManyPeople

{

  public static void Main()

  {

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

      test(i);

  }

 

  public static void test(int iIter)

  {

    DateTime start = DateTime.Now;

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

      new ManyPeople().Average();

    DateTime finish = DateTime.Now;

    Console.WriteLine("Total time for iteration " + iIter + ": " + (finish - start));

  }

 

  private long Average()

  {

    ArrayList list = new ArrayList(100000);

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

      list.Add(new Person(i, "John " + i));

 

    long silly = 0;

    foreach (Person p in list)

      silly += p.Id;

    return silly / 100000;

  }

}

 

// Person.cs: a very simple guy

public class Person

{

  int id;

  string name;

 

  public Person(int anId, string aName)

  {

    this.id = anId;

    this.name = aName;

  }

 

  public int Id

  {

    get { return this.id; }

  }

}

Java:

// Java Create 100,000 people in an ArrayList and access them

import Java.util.*;

 

public class ManyPeople

{

  public static void main(String[] args)

  {

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

      test(i);

  }

 

  public static void test(int iIter)

  {

    long start = System.currentTimeMillis();

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

      new ManyPeople().average();

    long finish = System.currentTimeMillis();

    System.out.println("Total time for iteration " + iIter + ": " + (finish - start));

  }

 

  private long average()

  {

    ArrayList list = new ArrayList(100000);

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

      list.add(new Person(i, "John " + i));

 

    long silly = 0;

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

      silly += ((Person)list.get(i)).getId();

    return silly;

  }

}

 

// Person.Java: a very simple guy

class Person

{

  private int id;

  private String name;

 

  public Person(int anId, String aName)

  {

    this.id = anId;

    this.name = aName;

  }

 

  public int getId()

  {

    return this.id;

  }

}

Cameron所用的测试机器是P3 1GHz1G内存的笔记本,操作系统是Windows 2000 SP2。下列是在.NET上测试的结果(取最好的6次):

.NET 1.0sp2:

ManyPeople
  
  
Total time for iteration 0: 00:00:07.3004976
  
  
Total time for iteration 1: 00:00:07.0501376
  
  
Total time for iteration 2: 00:00:07.2504256
  
  
Total time for iteration 3: 00:00:07.7311168
  
  
Total time for iteration 4: 00:00:07.5007856
  
  
Total time for iteration 5: 00:00:07.5007856
  
  

.NET 1.1:

ManyPeople
   
   
Total time for iteration 0: 00:00:08.0916352
  
  
Total time for iteration 1: 00:00:08.5222544
  
  
Total time for iteration 2: 00:00:08.3520096
  
  
Total time for iteration 3: 00:00:08.6324128
  
  
Total time for iteration 4: 00:00:08.3419952
  
  
Total time for iteration 5: 00:00:08.1617360
  
  

可以看到,同样的代码在.NET 1.1上比.NET 1.0 SP2上慢了大约15%。这是一个很奇怪的现象。并且,Cameron观察到,.NET上同样代码的运行速度并不随运行次数的增加而提高,说明.NET CLR只是简单地进行了JIT编译。而在Hotspot Server上,不仅开始时的性能就有优势,而且速度还会不断提高:

Sun Hotspot Server JVM from JDK 1.4.1_02:

Java -server -Xms128m -Xmx128m ManyPeople
   
   
Total time for iteration 0: 6370
  
  
Total time for iteration 1: 5788
  
  
Total time for iteration 2: 5868
  
  
Total time for iteration 3: 6029
  
  
Total time for iteration 4: 5748
  
  
Total time for iteration 5: 5738
  
  
Total time for iteration 6: 5729
  
  
Total time for iteration 7: 5948
  
  
Total time for iteration 8: 5688
  
  
Total time for iteration 9: 5679
  
  
Total time for iteration 10: 5658
  
  
Total time for iteration 11: 6028
  
  
Total time for iteration 12: 5699
  
  
Total time for iteration 13: 5708
  
  
Total time for iteration 14: 5678
  
  
Total time for iteration 15: 5969
  
  
Total time for iteration 16: 5628
  
  
Total time for iteration 17: 5538
  
  
Total time for iteration 18: 5608
  
  
Total time for iteration 19: 5498
  
  
Total time for iteration 20: 5768
  
  
Total time for iteration 21: 5518
  
  
Total time for iteration 22: 5307
  
  
Total time for iteration 23: 4247
  
  
Total time for iteration 24: 4696
  
  
Total time for iteration 25: 4617
  
  
Total time for iteration 26: 4777
  
  
Total time for iteration 27: 4286
  
  
Total time for iteration 28: 4677
  
  
Total time for iteration 29: 4626
  
  
Total time for iteration 30: 4697
  
  
Total time for iteration 31: 4286
  
  
Total time for iteration 32: 4697
  
  
Total time for iteration 33: 4617
  
  
Total time for iteration 34: 4696
  
  
Total time for iteration 35: 4307
  
  
Total time for iteration 36: 4686
  
  
Total time for iteration 37: 4807
  
  
Total time for iteration 38: 4517
  
  
Total time for iteration 39: 4306
  
  
Total time for iteration 40: 4657
  
  
Total time for iteration 41: 4807
  
  
Total time for iteration 42: 4596
  
  
Total time for iteration 43: 4206
  
  
Total time for iteration 44: 4777
  
  
Total time for iteration 45: 4717
  
  
Total time for iteration 46: 4607
  
  
Total time for iteration 47: 4196
  
  
Total time for iteration 48: 4796
  
  
Total time for iteration 49: 4707
  
  
Total time for iteration 50: 4777
  
  
Total time for iteration 51: 4196
  
  
Total time for iteration 52: 4627
  
  
Total time for iteration 53: 4687
  
  
Total time for iteration 54: 4806
  
  
Total time for iteration 55: 4186
  
  
Total time for iteration 56: 4627
  
  
Total time for iteration 57: 4697
  
  
Total time for iteration 58: 4807
  
  
Total time for iteration 59: 4166
  
  
Total time for iteration 60: 4616
  
  
Total time for iteration 61: 4697
  
  
Total time for iteration 62: 4717
  
  
Total time for iteration 63: 4346
  
  
Total time for iteration 64: 4717
  
  
Total time for iteration 65: 4617
  
  
Total time for iteration 66: 4626
  
  
Total time for iteration 67: 4367
  
  
Total time for iteration 68: 4706
  
  


<script type="text/javascript">
 
 
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
 
 
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
搭建网站是现代社会中非常重要的技能,对于想要在网上展示自己的个人或商业项目而言,手把手搭建网站是一种非常有效的方法。在csdn.net上,你可以找到许多相关资源和教程,以下是一些基本步骤和注意事项: 首先,你需要了解网站的目的和类型。这将有助于你选择合适的平台和工具。例如,如果你想要一个博客类型的网站,你可以选择WordPress、Typecho等。如果你想要一个电子商务网站,你可以选择Magento、WooCommerce等。 其次,你需要选择一个网站主机服务。在csdn.net上,你可以找到许多常见的主机服务提供商的评测和推荐。选择合适的主机服务可以确保你的网站稳定运行和良好的性能。 接下来,你需要选择一个合适的域名并注册。域名代表着你的网站的网址。确保选择一个简洁、易记和与你的网站主题相关的域名。 之后,你可以开始设计和开发你的网站。在csdn.net上,你可以找到许多网页设计和前端开发的教程和资源。你可以学习HTML、CSS和JavaScript等技术,并使用相关的开发工具来编写网页代码。 完成网站的设计和开发后,你可以将网页文件上传到你的主机服务提供的服务器上。这样,你的网站就可以通过域名访问了。 最后,你可以继续优化和改进你的网站。使用合适的SEO技巧可以增加网站的曝光度和访问量。此外,你还可以添加其他功能和插件,如社交分享按钮、在线聊天等,以提升用户体验。 总之,在csdn.net上有许多关于如何手把手搭建网站的资源,从选择平台到设计开发再到优化改进,你都可以找到相关的教程和指南。通过参考这些资源并自己动手实践,你可以掌握搭建网站的技能,并成功创建出一个令人满意的网站。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值