TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Benchmark: C++ vs C#

78 pointsby progalmost 14 years ago

12 comments

cagefacealmost 14 years ago
<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 未加载
bitdiffusionalmost 14 years ago
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_Palmost 14 years ago
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 未加载
ghennealmost 14 years ago
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_salmost 14 years ago
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.
kevingaddalmost 14 years ago
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 未加载
pragmaticalmost 14 years ago
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.
adolgertalmost 14 years ago
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.
peacemakeralmost 14 years ago
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_laoalmost 14 years ago
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 未加载
lutormalmost 14 years ago
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++.
omousealmost 14 years ago
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).