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. spring 技巧集锦

    SpringBoot四大神器之Actuator actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看.相关功能统计等. <dependenc ...

  2. 【b603】作业调度方案

    Time Limit: 1 second Memory Limit: 50 MB [问题描述] 我们现在要利用m台机器加工n个工件,每个工件都有m道工序,每道工序都在不同的指定的机器上完成.每个工件的 ...

  3. MapReduce自定义InputFormat,RecordReader

    MapReduce默认的InputFormat是TextInputFormat,且key是偏移量,value是文本,自定义InputFormat需要实现FileInputFormat,并重写creat ...

  4. hdu1693插头dp(多回路)

    题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃全然部的树,求有多少中方法. 这题是插头dp,刚刚学习,不是非常熟悉,研究了好几天才明确插头dp的方法,他们老是讲一些什 ...

  5. DapperPoco

    DapperPoco -- 基于Dapper的.轻量级的.高性能的.简单的.灵活的ORM框架 为什么要重复造轮子 因为现有的轮子都在某些方面不太令我满意,下面我来一一点评一下,欢迎拍砖. Entity ...

  6. Linux 下的任务管理 —— ps、top

    ps:report a snapshot of the current processes. ps 命令支持三种使用的语法格式 UNIX 风格,选项可以组合在一起,并且选项前必须有"-&qu ...

  7. WPF 使用 Edge 浏览器

    原文:WPF 使用 Edge 浏览器 版权声明:博客已迁移到 http://lindexi.gitee.io 欢迎访问.如果当前博客图片看不到,请到 http://lindexi.gitee.io 访 ...

  8. 浅谈java枚举类

    一.什么情况下使用枚举类? 有的时候一个类的对象是有限且固定的,这种情况下我们使用枚举类就比较方便? 二.为什么不用静态常量来替代枚举类呢? public static final int SEASO ...

  9. uinty3d导入错误问题解决

    导入第一被复制到文件unity3d在相应的文件夹的安装文件夹.回归后,unity3d软体.正确的选择"输入". 版权声明:本文博主原创文章.博客,未经同意不得转载.

  10. tomcat中同时部署两个项目的问题

    其中一个项目总是无法访问. 参考这两篇文章: 1. tomcat中同时部署两个项目的问题 2. java.lang.IllegalStateException: Web app root system ...