C# vs C++

G

Guest

Is there a difference of opinion between C# users and C++ users as to whether
C# is generally a replacement for C++? I asked this in the C++ thread and
most people people who responded say that C# is not a replacement for C++.

Do C# promoters have a different view?
 
J

John Timney \( MVP \)

Its not an replacement but I would say for many projects its certainly an
alternative to traditional C++, and typically a lot faster to develop with
in the .NET IDE.

The resulting exeecutables are not as fast as native C or C++ (if you know
how to write C/++ of course) but its a very fast language to pick up and run
with, thus it has many advantages over coding in C++.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
G

Guest

Thank you, yes it seems like C# is a great language to RAD prototype
something iteratively and then one can always convert it to C++.
--
Greg McPherran
www.McPherran.com


John Timney ( MVP ) said:
Its not an replacement but I would say for many projects its certainly an
alternative to traditional C++, and typically a lot faster to develop with
in the .NET IDE.

The resulting exeecutables are not as fast as native C or C++ (if you know
how to write C/++ of course) but its a very fast language to pick up and run
with, thus it has many advantages over coding in C++.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
L

Lloyd Dupont

Thank you, yes it seems like C# is a great language to RAD prototype
something iteratively and then one can always convert it to C++.

If it is to convert to MC++ there is no reason (MC++ use MSIl as much as
C#).
If it is to convert to plain old C++, good luck... you should say: "one
could always spend Aeons convert it to C++"
 
J

Jim Holmes

Is there a difference of opinion between C# users and C++ users as to
whether C# is generally a replacement for C++? I asked this in the C++
thread and most people people who responded say that C# is not a
replacement for C++.

Do C# promoters have a different view?

Check out Kate Gregory's blog at http://www.gregcons.com/KateBlog/default.aspx.
She's a passionate promoter of of C++ and her thoughts are well worth reading.
 
B

Bob Powell [MVP]

It takes me less than half the time to develop a program in C# than it does
to develop the equivalent functionality in C++. I still can't write a low
level driver in C# tough...

Horses for courses.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
R

Richard Grimes

John said:
The resulting exeecutables are not as fast as native C or C++ (if you
know how to write C/++ of course) but its a very fast language to
pick up and run with, thus it has many advantages over coding in C++.

Done any comparisons? Try it, you might be surprised.

I did some comparisons and was surprised and showed them to someone on
the C++ team and he told me that they were just what he expected.

The problem is that when most people think of .NET they think
'interpreter', or 'Java', or godforbid, Visual Basic. And so they think
'bad performance'. They shouldn't.

I think of the JIT compiler as being the back end of a C++ compiler (it
was written by people from the C++ team). If you discount the time that
the JIT compiler takes then for fully trusted code there is no reason
why it should be significantly slower than code generated by the
unmanaged C++ compiler. The only possible issue may be garbage
collection.

Of course, if you know of other areas of the .NET runtime which are
significantly slower than the equivalent in Win32 then you should post
them here so that we all can avoid using them <g>.

Richard
 
R

Richard Grimes

Bob said:
It takes me less than half the time to develop a program in C# than
it does to develop the equivalent functionality in C++. I still can't
write a low level driver in C# though...

You still cannot (should not) in managed C++ either <g>.

But I am not sure if the OP is referring to C++ in general, or to
managed C++.
Horses for courses.

.... and for glue when they are knackered ;-)

Richard
 
M

Marc Noon

A good litmus test would be to write a prime number generator.

Then after 10000 or so just see how long it took in c# and c++.

Marc N.
--
In all the universe, and in all of space, resides a time and a place, when
you blink, let it be, in a sequence of events.

Bob Powell said:
It takes me less than half the time to develop a program in C# than it
does to develop the equivalent functionality in C++. I still can't write a
low level driver in C# tough...

Horses for courses.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
J

John Timney \( MVP \)

I think the average figure I saw being spoken about was to expect up to 20%
slower. Not significant, and certainly with the increased productivity
something that can be worked on in budget if it was an issue. Personally,
I've not done a comparison to the levels you would have done Richard.

I know that some of the work I have been invoved in recently using native C
would have been unworkable in .NET as performance was the driving factor.
For me - as long as complete end to end performance was not the driving
factor I would choose c# over c/++ anytime.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
J

Jon Skeet [C# MVP]

Marc Noon said:
A good litmus test would be to write a prime number generator.

Then after 10000 or so just see how long it took in c# and c++.

Well, that's a good litmus test if your application is going to be
processor intensive in a maths kind of way. I suspect that most
applications don't actually have a bottleneck like that. I suspect most
applications fall into one or more categories:

1) No real bottleneck - performance is perfectly acceptable
2) Database bottleneck
3) Network bottleneck
4) Graphics bottleneck (which may be processor related, but in a more
framework dependent way, eg using a framework which doesn't have
hardware acceleration)
 
J

Jon Skeet [C# MVP]

Jon Skeet said:
Well, that's a good litmus test if your application is going to be
processor intensive in a maths kind of way. I suspect that most
applications don't actually have a bottleneck like that. I suspect most
applications fall into one or more categories:

1) No real bottleneck - performance is perfectly acceptable
2) Database bottleneck
3) Network bottleneck
4) Graphics bottleneck (which may be processor related, but in a more
framework dependent way, eg using a framework which doesn't have
hardware acceleration)

I missed one I'd thought of before: memory bottlenecks, where you have
to control the memory allocation really, really tightly. (Embedded
systems etc.)
 
S

Scherbina Vladimir

Greg said:
Thank you, yes it seems like C# is a great language to RAD prototype
something iteratively and then one can always convert it to C++.

It will take a big amount of time. At least because c# has different syntax,
and in c++ you should watch for commiting / releasing of memory, etc.
Yes, for a small project it would not be diffcult to convert C# code to C++,
but imagine corporate application that has a thousands of lines of code. You
will need many men-moon and time.
 
L

Lloyd Dupont

Another comparison.
I wrote my own rich text editor, not derived from TextBoBase, but from
Control, and handling international character through uniscribe.

If I copy paste 400Kb of text It takes roughly the same amount of time
(~1second) to do all the layouting and drawing and 20% more memory than
MS-Word.

I could tell now that I no longer believe this bullshit about .NET being
inneficient.

The certainly profile their code in C, do the same in C# and you would yield
similar results!
 
R

Richard Grimes

Marc said:
A good litmus test would be to write a prime number generator.

Then after 10000 or so just see how long it took in c# and c++.

I did it with a Fast Fourier Transform, compiled as managed C++ and
native C++. I ran the managed C++ library once before running it through
a timing loop (this was to discount the effect of JIT compilation).

Somewhere I have the results, but they varied depending on the
optimization switches I used. The fastest time was for one of the
managed C++ builds, but only just.

Richard
 
R

Richard Grimes

Jon said:
1) No real bottleneck - performance is perfectly acceptable
2) Database bottleneck
3) Network bottleneck
4) Graphics bottleneck (which may be processor related, but in a more
framework dependent way, eg using a framework which doesn't have
hardware acceleration)

Actually, in most cases the bottleneck is the user <g>. The application
has to wait for user imput. But I agree with you and this is why I
jumped on John for saying that .NET is slower, because 1) it isn't (I
will post results later today to show this) and 2) in many cases the
slight differences between .NET and unmanaged code is insignificant
anyway.

The one thing that might make a difference is memory allocation.
Allocation is a lot quicker in .NET than in unmanaged code, but when the
GC kicks in the .NET code gets a big hit.

Richard
 
R

Richard Grimes

John Timney ( MVP ) said:
I think the average figure I saw being spoken about was to expect up to
20% slower. Not significant, and certainly with the increased
productivity something that can be worked on in budget if it was an
issue. Personally, I've not done a comparison to the levels you would
have done Richard.

I don't know where you got that figure from, but it is nowhere near the
figure I was told. Here are my comparisons for v2.0:

http://www.grimes.demon.co.uk/dotnet/man_unman.htm

For code that is not optimized or code that is optimized for space
managed C++ is *quicker* than unmanaged code (native code takes 138% the
time of that managed code takes). In the case of optimized for speed,
the managed code takes 4% more time, so it is only slightly slower than
managed code.

I performed these measurements two years ago for v1.1 and I got a figure
of 6% longer for speed optimised managed C++ over speed optimized native
C++. I showed this to the guy responsible for performance on the C++
team and his comment was 'that looks right'. No one mentioned a figure
of 20%, and as my measurements for a computationally intensive routine
show, a figure of 20% is far too high.

In the best case native code has a mere 4% advantage over managed code.
I know that some of the work I have been invoved in recently using
native C would have been unworkable in .NET as performance was the
driving factor.

If it involves direct memory manipulation (which is what C was designed
to do) then I agree, but only because .NET makes a point of trying to
prevent you from performing direct memory access. If it uses
manipulation of arrays of values then C is not likely to be
significantly faster than a managed language. Furthermore, your C#
development will take a lot less time than the C development, which is
the whole point of .NET - it is now being marketed as a RAD solution.
For me - as long as complete end to end performance was not the
driving factor I would choose c# over c/++ anytime.

I think you should take 'performance' out of your criteria because it
really is irrelevant in this discussion. .NET is NOT significantly
slower than native code. There are places where it is inappropriate (for
example device drivers and IMO services), but in terms of performance
you'll not notice a 4% difference.

Richard
 
R

Richard Grimes

Scherbina said:
Each task has it's instruments. an interesting article about .net
applications:
http://www.sysinternals.com/blog/2005/04/coming-net-world-im-scared.html

Thanks, that is an excellent article and it fits in with what a lot of
people have been telling me about the usage of .NET in Vista (it uses
too much memory, so Microsoft are keeping the .NET usage in Vista as low
as they can, and certainly they are keeping it out of anything that
matters like the shell and system services).

Here's an article I have written about .NET usage in Vista:

http://www.grimes.demon.co.uk/dotnet/vistaAndDotnet.htm

Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top