TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Benchmark: C++ vs C#

78 点作者 prog将近 14 年前

12 条评论

cageface将近 14 年前
<i>The results seem conclusive: if you're developing software for the desktop, and (like me) you are equally skilled in C# and C++, it's safe to take advantage of the simpler syntax, rich standard libraries, stellar IntelliSense and reduced development effort that C# offers.</i><p>With the glaring exception of numeric code, which is the most crucial thing for a lot of apps that are now written in C++. You'd be crazy to write a native CRUD app in C++ now but most of the big C++ apps I can think of do heavy work in numerics (Photoshop, Ableton, Maya, etc).
评论 #2674103 未加载
评论 #2674404 未加载
bitdiffusion将近 14 年前
The poor guy is taking a beating in the code-project comments which is a pity since he obviously spent some time putting it together. In a comparison like this, you are always going to get people on either side of the fence claiming the results are invalid because there was some compiler switch or code construct that was missed.<p>The language-agnostic version of this article: you can write slow code in any language.
评论 #2674926 未加载
S_A_P将近 14 年前
I have heard that you can expect a 10-15% difference in most cases. However, it seems that there are just some arenas that C# wont quite measure up. I'm thinking multimedia applications would not scale well. Mainly because there is no way via Microsoft's .NET implementation to access SSE or other processor intrinsics. I know that mono announced that this a year or two ago, anyone have experience with it?
评论 #2674129 未加载
ghenne将近 14 年前
We've been aware of how slow CF is on Windows CE for a while. Here are some benchmarks we have run:<p>CuWin 3500, CE5, NS Basic/CE 8 NS Basic/CE: 26529 loops/second Microsoft .NET: 133 loops/second<p>Acer beTouch E101 Windows Mobile 6.5, 528 mhz, NS Basic/CE 8.0 NS Basic/CE: NS Basic/CE: 16669 loops/second Microsoft .NET: 3060 loops/second<p>CuWin 5500, CE6, NS Basic/CE 8 NS Basic/CE: 14394 loops/second Microsoft .NET: 764 loops/second<p>i-mate 400mhz, WM5, NS Basic/CE 8.0 NS Basic/CE: 12632 loops/second Microsoft .NET: 1290 loops/second<p>Running the same test under NS Basic/App Studio, an iPhone 4 scores 282,674, Nexus One is 403,000 and the Motorola Xoom is 718,484. Plainly, Windows CE.NET has a long way to go!
scott_s将近 14 年前
He did not say if optimizations were turned on for the debug builds, and I'm not familiar enough with Visual C++ to know what the defaults are. You can still have DEBUG defined so that asserts are compiled in when optimizations are on. However, looking at the results, I suspect optimizations were turned off, which makes those results meaningless.
kevingadd将近 14 年前
The benchmark numbers for the Compact Framework on ARM make this a lot more interesting. I used it on PowerPC (the XBox 360 .NET runtime used by XNA is based on the Compact Framework), and I was uncertain whether the issues were related to the PowerPC architecture. It looks like the Compact Framework is just bad.
评论 #2673981 未加载
pragmatic将近 14 年前
I think C# is in the category of "fast enough".<p>When I was working through project Euler (<a href="http://projecteuler.net/" rel="nofollow">http://projecteuler.net/</a>) with various languages, the only one I really had to optimize was Python (vs C/C#/Haskell).<p>I really like Python, and for most stuff it's fast enough. Just saying the real penalty (that I noticed) is a scripting language, _if_ it's heavily arithmetically constrained.<p>Some (non-trivial) games in C#: <a href="http://www.arcengames.com/w/index.php/aiwar-alienbundle" rel="nofollow">http://www.arcengames.com/w/index.php/aiwar-alienbundle</a><p><a href="http://murudai.com/solar/" rel="nofollow">http://murudai.com/solar/</a><p>However, it's possible and even practical to also write games in Python. See the pygame project.
adolgert将近 14 年前
This article raises interesting questions. He has done low-level tests which do not read much from the data or instruction pipelines, so these tests show compiled MSIL can be better optimized than C++. C++ is prone to accidental performance deficits from problems like aliasing, so that makes sense.<p>Now I want to see higher-level tests, where algorithms reading significant data or application-level benchmarks are run. The faster the CPU core, the less penalty there will be from C# compilation. The problem is that it would take lots of time to translate something like WORF, GAMESS, or other standard numerical benchmarks.
peacemaker将近 14 年前
I think he hit the nail on the head referring to c# programmers in general not being as "performance conscious" which leads the misconception that c# is a much slower language to use. I've worked in many places and have come across the same thing. As a c++ programmer I have also worked with c# coders and am often shocked at their slap-dash approach to software engineering. I'm not saying they're all like that but it seems to be a common trend in my opinion!
评论 #2674169 未加载
评论 #2674157 未加载
评论 #2674362 未加载
评论 #2674418 未加载
评论 #2674250 未加载
shin_lao将近 14 年前
This benchmark is totally wrong as you can read in the comments of the page.<p>Basically he didn't turn on all optimizations on the C++ program and used the "slow but secure" version of the Microsoft STL.<p>Also his GenericSum uses array in C++ and lists in C#, so the C++ has to reallocate at each append.<p>I could go on for long, I appreciate the intent, but all you need to know is that Microsoft gave up on using C# everywhere because it's damn too slow.
评论 #2675171 未加载
评论 #2676157 未加载
lutorm将近 14 年前
I don't know much C#, but it seems to me there are so many ways of writing "numeric" code in C++. Using the STL algorithms is one, using C-style looks on POD arrays another, and using an expression template math library like blitz yet another. You can't really say that any one of them, except possibly the expression template method, is uniquely C++.
omouse将近 14 年前
Even though the benchmark is incorrect, the flawed conclusion should lead you to see that Java is just as good a solution as C# (possibly better since it runs officially on more platforms).