评测报告:.NET的性能仍然远远落后于Java<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
每个人都看过各种不同的benchmark,有证明.NET比Java快的,也有证明Java比.NET快的。在某些人的手里,benchmark是一面魔镜,透过它能看到想看的东西。所以,当这位名为Cameron的先生要开始在.NET和Java之间做一个benchmark时,他认为自己就是在浪费时间,因为肯定会有人来证明.NET比Java快。
顺便地,Cameron先生提出了10条“不要用于在.NET和Java之间做选择”的理由,其中包括:
Ø 在某一组特定的benchmark中,某一个比另一个快一点;
Ø Microsoft或Sun(或者Oracle、IBM……)的报告说其中一个比另一个好得多;
Ø 你喜欢(或不喜欢)Bill Gates或者Scott McNeally(或者Larry Ellison);
Ø 你认为Microsoft或者Sun(或者IBM或者Oracle)很邪恶(或者很伟大);
Ø 你在TheServerSide.com或者GotDotNet.com(或者Microsoft.com)读了一篇“没有偏见”的文章;
实际上,这次benchmark源于Cameron与tRolf两人在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 1GHz、1G内存的笔记本,操作系统是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
Total time for iteration 69: 4617
Total time for iteration 70: 4617
Total time for iteration 71: 4366
Total time for iteration 72: 4687
Total time for iteration 73: 4616
Total time for iteration 74: 4196
Total time for iteration 75: 4787
Total time for iteration 76: 4687
Total time for iteration 77: 4807
Total time for iteration 78: 4436
Total time for iteration 79: 4387
Total time for iteration 80: 4676
Total time for iteration 81: 4807
Total time for iteration 82: 4417
Total time for iteration 83: 4296
Total time for iteration 84: 4686
Total time for iteration 85: 4797
Total time for iteration 86: 4266
Total time for iteration 87: 4697
Total time for iteration 88: 4617
Total time for iteration 89: 4717
Total time for iteration 90: 4276
Total time for iteration 91: 4707
Total time for iteration 92: 4616
Total time for iteration 93: 4697
Total time for iteration 94: 4296
Total time for iteration 95: 4677
Total time for iteration 96: 4546
Total time for iteration 97: 4697
Total time for iteration 98: 4296
Total time for iteration 99: 4677
可以看到,随着运行次数的增加,Sun Hotspot Server不断将领先优势拉大,最后几乎比.NET 1.1快了一倍。.NET CLR始终无法将运行时间降低到8秒以下,而Sun Hotspot Server在多次运行之后则可以保持在5秒以下。因此,Cameron认为,对于大运算量的应用程序,Hotspot JVM比Microsoft CLR要快得多。
原文及完整的benchmark数据请看Cameron的blog:
http://www.freeroller.net/page/cpurdy/20030516
分享到:
相关推荐
先评测,再优化,专注优化瓶颈,重视性能,保持性能导向思维
测评报告:2021年中国植物肉测评报告(34页).pdf
测评报告:2021年中国植物肉测评报告.pdf
性能优化手册是一套java性能学习研究小技巧,包含内容:Java性能优化、JVM性能优化、服务器性能优化、数据库性能优化、前端性能优化等。 内容包括但不限于: String 性能优化的 3 个小技巧 HashMap 7 种遍历方式...
马斯克给了全世界一个D DAY的猜想,随后揭晓的是一台四驱纯电动的P85D,并拥有一定程度的自动驾驶。本文可能是特斯拉 P85D 的第
相比于JAVA是一个标准,.Net是一个架构,它包含了在操作系统上开发软件的所有层次,为集成任意平台上的显示技术、组件技术、数据驱动技术提供了丰富的层次。.net实际上封装了操作系统的部分功能,如文件处理和内存...
性能优化手册是一套java性能学习研究小技巧,包含内容:Java性能优化、JVM性能优化、服务器性能优化、数据库性能优化、前端性能优化等。 内容包括但不限于: String 性能优化的 3 个小技巧 HashMap 7 种遍历方式...
威盛电子 第三方评测报告:威盛Nano X2处理器与英特尔Atom处理器之比较(中英文)rar,威盛电子 第三方评测报告:威盛Nano X2处理器与英特尔Atom处理器之比较(中英文)
作为大学生综合素质测评信息管理系统,在系统中一定存在许多的学生,这需要对学生的信息进行管理; 每学期期末时都需要对这些学生的各方面素质进行综合测评,系统能根据各个素质的分数自动计算综合的 素质分数,...
基于ASP.NET的高校学生综合测评系统的设计与实现,夏天河,陈金玉,高校综合素质测评系统是基于ASP.NET MSSQL,采用B/S三层体系架构。本文简单介绍了系统开所涉及的相关技术,着重介绍测评体系建立的规��
使用C#.net写的教师在线测评系统,分三个模块,分别是学生登陆,教师登陆及管理员登陆
pageadmin cms4.0完全更新之前版本的后台,后台简洁...运行环境要求:程序版本:PageAdmin V4.0 开发语言:.Net数据库:Mssql2008、mssql2012及以上操作系统: Win7/win8或上运行环境:IIs+Asp.net4.0、FrameWork4.6.1
dotnet学生毕业评测试卷,包括C#基础语法、WINFORM、ASP.NET、职素、英语等内容
基于.NET的大学生综合测评系统.docx
后台管理页面主要包括:学生管理、教师管理、教学内容管理、学校新闻管理,简介管理、教学资源管理、课程管理、评测主题管理,教师评测得分管理等管理模块。 (3)教师模块 输入教师的姓名和密码后,进入教师管理...
《 信息安全测评理论与技术》 专辑 《 信息安全测评理论与技术》 专辑《 信息安全测评理论与技术》 专辑
计算机毕业设计 综合测评计算是每学期必不可少的工作。...该论文主要介绍了网络上最受欢迎的Java Applet技术、系统的分析设计、各个功能模块的实现、系统的测试调试、以及系统开发过程中遇到的问题和问题的解决。
本文介绍了动态编译简史以及动态编译与评测的关系,为编写好评测,优化编译器要擅长找出死代码清除死代码--对于程序执行的输出没有作用的代码。如果您想测量X的性能,一般情况下您是想测量它编译后的性能,而不是它...