tags:

views:

475

answers:

5

Is C++/CLI faster than C#? In which type of operations is it faster? Thanks!

+7  A: 

Since they both run on the .NET framework, I'd say any performance difference would be negligable. Any difference will almost certainly be down to how well whichever compilers you are using work.

Peter
+1  A: 

Seeing as they are both .NET languages that get compiled into the same byte code that in turn gets run on the same virtual machine I'd say in general, no.

C++/CLI is really only intended to provide language interop between .NET and C++.

Andrew Khosravian
C++/CLI is a full fledged language in its own right. It has some advantages over C#, even in a /clr:pure compilation environment.
Reed Copsey
I think much effort was dedicated on this product. It is hard to think it was only intended for interop operations.
+1  A: 

Any managed code written in C++/CLI will essentially be exactly the same as the equivalent C#, assuming compiler accuracy, as they'll both end up as intermediate language instructions. However, C++/CLI makes it easy to mix unmanaged code in with the managed portion which may provide considerable speed benefits if well optimised.

Stu Mackellar
+1  A: 

Well, the short answer is no. Why? Reference types in C++/CLI are compiled to MSIL, same as in C#.

The nice thing about C++/CLI (and the long answer) though, is that you can easily call into native code, which (in many cases) is faster. That being said, if you write a native C++ class and expect it to be executed natively when called by someone in a managed class, that native C++ class must be compiled without CLR support (this question goes into how to do that).

unforgiven3
+9  A: 

Not necessarily. However, C++/CLI takes away much of the syntactic sugar around non-performant ways of doing things that is present in C# (boxing for example).

Also, C++/CLI allows you a much more clean interop with unmanaged code, actually allowing you to mix managed / unmanaged code, which is a performance crucial environment may be of benifit.

EDIT:

See this post for some of the differences: http://msdn.microsoft.com/en-us/library/ms379617%28VS.80%29.aspx

LorenVS
Very good point about the lack of C#'s syntactic sugar.
unforgiven3
Thanks, bit of a different way of looking at things, but I suppose its a performance benefit as it helps you write performant code
LorenVS
Then again, C++/CLI introduces syntactic sugar of its own for things like imitating stack allocation and RAII via `Dispose` calls.
Pavel Minaev
I don't get why C++/CLI would be faster than writing exactly the same code on c# with interop. Of course when developing it comes in handy to have the native functions at hand without having to declare dllimport's and so, but from the moment you have the dllimport's defined, why would c++/cli code be any faster?
devoured elysium