05年时,在微软的Rico Mariani做了一次实际应用的C#和C++的性能比较。事情起源于微软著名的元老Raymond Chen(在下敬仰的超级牛人)用C++写了一个英汉词典程序,来描述讲解优化C++程序的过程。他从一个代码简单直观的版本开始,不断测试优化,直到达到满意的性能。Rico Mariani使用相同的方式,但是使用C#做了相同的程序。结果是,Mariani的最初的简单直观版本的速度几乎是Chen的最初C++版本的十倍;而对于优化的终极版本,Chen重写了文件IO,重写了字符串类,使用了自定义的内存分配器,使得C++版本的速度是C#版本的两倍。

简单的说C#的设计目标之一就是可以使简单直观的代码具有较高的效率,而且它确实实现了这个目标;而C++允许我们使用任何手段来提高效率,只要愿意做出足够的努力。

原文:

A few years ago, Rico Mariani (at Microsoft) did really interesting performance comparison between C# and C++.

It started when Raymond Chen (one of the most important engineers at Microsoft, and in the CS universe generally) wrote a Chinese/English dictionary application in C++ to illustrate his process for optimizing C++ code. He started with a simple, intuitive version of the code, and then he incrementally profiled and optimized the bottlenecks until he was happy with the performance.

Rico Mariani took a similar tack, writing a simple, intuitive version in C#, and then optimizing its bottlenecks.

Surprisingly, Mariani's original C# implementation is almost ten times as fast as Chen's original C++ implementation, without having to resort to any counterintuitive hacks.

Eventually, Chen rewrote the file I/O library, implemented his own string class, and used a custom memory allocator. Only AFTER jumping through all those hoops, the C++ version was about twice as fast as the C# version.

The moral of the story is that C++ gives you the tools to write blazingly fast software, if you're willing to do a lot of non-standard programming, and use a LOT of hacks.

C#, on the other hand, lets you write really really fast software right out of the gate, without resorting to any oddball shenanigans. But if you want to reach maximum possible performance, you will hit a wall sooner with C# than you would with C++. Additionally, a piece of software in C# will almost always have greater memory requirements than an equivalent C++ program.

There's a summary of the story on Coding Horror, here:

http://blogs.msdn.com/ricom/archive/2005/05/10/performance-quiz-6-chinese-english-dictionary-reader.aspx

And you can read the whole play-by-play, here (follow all the links at the top of the page):

http://blogs.msdn.com/ricom/archive/2005/05/19/420158.aspx

BenjiSmith
Saturday, December 08, 2007

http://blog.csdn.net/nightmare/article/details/1932497

一次C#和C++的实际应用性能比较(C++允许我们使用任何手段来提高效率,只要愿意做出足够的努力)的更多相关文章

  1. In-Memory:内存数据库

    在逝去的2016后半年,由于项目需要支持数据的快速更新和多用户的高并发负载,我试水SQL Server 2016的In-Memory OLTP,创建内存数据库实现项目的负载需求,现在项目接近尾声,系统 ...

  2. 01.SQLServer性能优化之---水平分库扩展

    汇总篇:http://www.cnblogs.com/dunitian/p/4822808.html#tsql 第一次引入文件组的概念:http://www.cnblogs.com/dunitian/ ...

  3. 避免重复造轮子的UI自动化测试框架开发

    一懒起来就好久没更新文章了,其实懒也还是因为忙,今年上半年的加班赶上了去年一年的加班,加班不息啊,好了吐槽完就写写一直打算继续的自动化开发 目前各种UI测试框架层出不穷,但是万变不离其宗,驱动PC浏览 ...

  4. 关于DOM的操作以及性能优化问题-重绘重排

     写在前面: 大家都知道DOM的操作很昂贵. 然后贵在什么地方呢? 一.访问DOM元素 二.修改DOM引起的重绘重排 一.访问DOM 像书上的比喻:把DOM和JavaScript(这里指ECMScri ...

  5. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  6. 故障重现(内存篇2),JAVA内存不足导致频繁回收和swap引起的性能问题

    背景起因: 记起以前的另一次也是关于内存的调优分享下   有个系统平时运行非常稳定运行(没经历过大并发考验),然而在一次活动后,人数并发一上来后,系统开始卡. 我按经验开始调优,在每个关键步骤的加入如 ...

  7. Fis3前端工程化之项目实战

    Fis3项目 项目目录结构: E:. │ .gitignore │ fis-conf.js │ index.html │ package.json │ README.md │ ├─material │ ...

  8. 【AR实验室】mulberryAR : ORBSLAM2+VVSION

    本文转载请注明出处 —— polobymulberry-博客园 0x00 - 前言 mulberryAR是我业余时间弄的一个AR引擎,目前主要支持单目视觉SLAM+3D渲染,并且支持iOS端,但是该引 ...

  9. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  10. Vue.js 和 MVVM 小细节

    MVVM 是Model-View-ViewModel 的缩写,它是一种基于前端开发的架构模式,其核心是提供对View 和 ViewModel 的双向数据绑定,这使得ViewModel 的状态改变可以自 ...

随机推荐

  1. Azure 与 AI

    微软 Build 2017 开发者大会:Azure 与 AI 的快速发展   欢迎大家持续关注葡萄城控件技术团队博客,更多更好的原创文章尽在这里~~ 一年一度的微软 Build 大会准时起航,本年度大 ...

  2. 【29.82%】【codeforces 703D】Mishka and Interesting sum

    [题解] 题意: 给n个数字组成有序数列; 给m个询问. 对于每个询问区间.输出这个区间里面出现次数为偶数次的所有数的异或值; 做法: 我们可以先求出这段区间里面所有(包括重复的数字)数字的异或值p1 ...

  3. 让ProgressDialog在setCancelable(false)时按返回键可dismiss

    最近发现Android4.0系统中ProgressDialog设置为setCancelable(true)时,点击ProgressDialog以外的区域也可以让ProgressDialog dismi ...

  4. 分布式缓存技术PK:选择Redis还是Memcached?

    作者:田京昆(腾讯后台研发工程师) 来源:腾云阁(https://www.qcloud.com/community/article/129) Memcached和Redis,作为近些年最常用的缓存服务 ...

  5. Bjarne Stroustrup语录2(一些C++使用注意点)

    一.致读者  1. 在编程序时,你是在为你针对某个问题的解决方案中的思想建立起一种具体表示.让程序的结构尽可能地直接反映这些思想:   ★.如果你能把“它”看成一个独立的概念,就把它做成一个类.    ...

  6. BIOS 选项设置的含义

    SATA Mode Section: ADHI: Advanced Host Controller Interface - this is a hardware mechanism that allo ...

  7. C#热敏打印图片 串口打印图片

    原文:C#热敏打印图片 串口打印图片 如图,一步一步慢慢调出来的 //串口通信类 public System.IO.Ports.SerialPort serialPort = null; serial ...

  8. linux 修改 ssh 的端口号,启动hg服务

    修改 ssh 的端口号 # vim /etc/ssh/sshd_config  将其中的 Port 改为 想要修改的端口号. # service sshd restart   启动hg服务 # hg ...

  9. C++杂记:运行时类型识别(RTTI)与动态类型转换原理

    运行时类型识别(RTTI)的引入有三个作用: 配合typeid操作符的实现: 实现异常处理中catch的匹配过程: 实现动态类型转换dynamic_cast. 1. typeid操作符的实现 1.1. ...

  10. 【Android】解决微信调起支付接口没反应,调不起来微信的问题

    原文:[Android]解决微信调起支付接口没反应,调不起来微信的问题 //#前言 吐槽一下,微信支付的sdk真难用,文档混乱,坑不少. 正文:可能引起这种情况的问题 1. 最不能出现的 你的APPI ...