C# vs C++ and .NET vs Mono vs Compact Framework performance tests

A detailed benchmark posted on codeproject investigates the performance of basic operations including string handling, hash tables, math generics, simple arithmetic, sorting, file scanning and (for C#) platform invoke of native code. These are the conclusions:

  • There is only a small performance penalty for C# on the desktop versus C++.
  • Mono is generally slower than Microsoft .NET but still acceptable, and all the benchmarks ran without modification.
  • The Compact Framework, an implementation of .NET for mobile devices, performs poorly.

My observations: this matches my own experiments. Why then do some .NET applications still perform badly? When Evernote switched its application from .NET to native code it got much better performance.

The main reason is a couple of issues that this kind of benchmark hides. One is the GUI layer, which involves a ton of platform invoke code under the covers. Another is the large size of .NET applications because of the runtime and library overhead; a lot more stuff gets loaded into memory.

One thing to like about Silverlight is that it is truly optimized for client programming and load time tends to be faster than for a desktop .NET application.

Note that for mobile these benchmarks suggest that C++ still has a big advantage. It would be interesting to see them applied to Silverlight apps on Windows Phone 7. As I understand it, the Silverlight .NET runtime in Windows Phone 7 shares code with the Compact Framework on Windows Mobile, so it is possible that the poor results for the Compact Framework would also apply to Silverlight on Windows Phone 7. Unfortunately developers do not have the option for C++ on Windows Phone 7.

6 thoughts on “C# vs C++ and .NET vs Mono vs Compact Framework performance tests”

  1. Interesting, thanks for the link Tim. I would have loved to see Delphi in there too, of course. I’m considering Mono for my next project (my first one where multi-platform would be a real advantage) and the relatively small disparity between it and ‘native’ C# .Net is encouraging, too.

  2. Thank’s for the link Tim.

    I would like to here Your opinion on the influence of the Garbage-Collector. In my applications, I am often recreating thousands of objects. The cleaning done by the garbage collector slows done the application significantly.

  3. “The Compact Framework, an implementation of .NET for mobile devices, performs poorly”

    No doubt, 100% agreed!

  4. This article by Gavin Clarke quotes Herb Sutter (MS C++ guy): “Managed languages like Java and .Net are still great, but the performance you give up when you use them is more important,” he says. “Look at smartphones – almost every first release says ‘managed only’, but version two says ‘native is important’. We want to wring the performance out of them.”

    Implying WP8 might include native C++ support?

    Vic

  5. @Vic I still think a future Win Phone will run on the same core OS as full Windows and yes, support native code dev.

    Tim

  6. When you KNOW how NETCF and SL works, you simply know about limitations and you must follow them. It is exactly the same as enterprise/desktop vs mobile JAVA. But no doubt, native is faster by brute force, even if application architecture is very poor… Very common approach is often used in Delphi, although I liked it also.

Comments are closed.