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. tomcat启动时自动加载一个类 MyServletContextListener

    目的: 我们知道在tomcat启动后,需要页面请求进行驱动来执行操作接而响应.我们希望在tomcat启动的时候能够自动运行一个后台线程,以处理我们需要的一些操作.因此需要tomcat启动时就自动加载一 ...

  2. Visual Studio - 为默认模板添加版权信息

    转自:http://www.cnblogs.com/easyzikai/archive/2012/10/14/2723328.html 和 http://www.cnblogs.com/eagle19 ...

  3. nditer —— numpy.ndarray 多维数组的迭代

    1. Single array iteration >>> a = np.arange(6).reshape(2,3) >>> for x in np.nditer ...

  4. Logical partitioning and virtualization in a heterogeneous architecture

    A method, apparatus, and computer usable program code for logical partitioning and virtualization in ...

  5. OpenGL(一)绘制圆、五角星、正弦曲线

    OpenGL入门之"顶点":OpenGL规定,一个多边形必须是一个"凸多边形",即连接多边形上任意两点,其连线都在多边形内部.多边形可以由其边上的端点(这里可称 ...

  6. OpenGL(二十二) gluBuild2DMipmaps 加载Mip纹理贴图

    当纹理被用于渲染一个面积比它本身小很多的对象时,会由于纹理图像的降采样率不足而导致混叠现象,主要的表现特征是纹理图像的闪烁,出现纹理躁动.特别是在场景远近移动变换时,这种闪烁情况更为明显,严重可能会影 ...

  7. 用Python模拟浏览器操作

    两种思绪三种要领: 用pamie.建议不要使用,因为pamie为小我私人开发,里面的bug比力多,并且是直接使用win32com体式格局的,如果ie不警惕修改了,后果很严重.另外,pamie3使用的是 ...

  8. poj 2763 Housewife Wind(树链拆分)

    id=2763" target="_blank" style="">题目链接:poj 2763 Housewife Wind 题目大意:给定一棵 ...

  9. JS判断android/IOS,并执行回调函数

    判断类型: var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') ...

  10. WPF特效-拼图游戏

    原文:WPF特效-拼图游戏 此文主要描述我实现碎片化的便捷过程. 步骤1:    选取参考图如下(百度图库搜的): 步骤2:    根据效果图或者模型构建贝塞尔曲线,为了方便查看效果,可以设置控制点, ...