By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,771 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,771 IT Pros & Developers. It's quick & easy.

C# vs C++

P: n/a
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?

--
Greg McPherran
www.McPherran.com
Dec 10 '05 #1
Share this Question
Share on Google+
33 Replies


P: n/a
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

"Greg" <gm@mcpherran.com> wrote in message
news:EC**********************************@microsof t.com...
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?

--
Greg McPherran
www.McPherran.com

Dec 10 '05 #2

P: n/a
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 )" wrote:
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

"Greg" <gm@mcpherran.com> wrote in message
news:EC**********************************@microsof t.com...
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?

--
Greg McPherran
www.McPherran.com


Dec 11 '05 #3

P: n/a
> 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++"
--
Greg McPherran
www.McPherran.com
"John Timney ( MVP )" wrote:
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

"Greg" <gm@mcpherran.com> wrote in message
news:EC**********************************@microsof t.com...
> 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?
>
> --
> Greg McPherran
> www.McPherran.com


Dec 11 '05 #4

P: n/a
"Greg" <gm@mcpherran.com> wrote in message
news:0B**********************************@microsof t.com...
and then one can always convert it to C++.


Why???
Dec 11 '05 #5

P: n/a
> 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.
Dec 11 '05 #6

P: n/a
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.

"Greg" <gm@mcpherran.com> wrote in message
news:EC**********************************@microsof t.com...
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?

--
Greg McPherran
www.McPherran.com

Dec 11 '05 #7

P: n/a
John Timney ( MVP ) wrote:
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
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 11 '05 #8

P: n/a
Bob Powell [MVP] wrote:
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
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 11 '05 #9

P: n/a
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 [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uE*************@TK2MSFTNGP09.phx.gbl...
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.

"Greg" <gm@mcpherran.com> wrote in message
news:EC**********************************@microsof t.com...
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?

--
Greg McPherran
www.McPherran.com


Dec 11 '05 #10

P: n/a
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

"Richard Grimes" <ri******@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
John Timney ( MVP ) wrote:
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
--
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
http://www.grimes.demon.co.uk/workshops/securityWS.htm

Dec 11 '05 #11

P: n/a
Marc Noon <no***@bellsouth.net> wrote:
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)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 11 '05 #12

P: n/a
Jon Skeet [C# MVP] <sk***@pobox.com> wrote:
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.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 11 '05 #13

P: n/a
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uE*************@TK2MSFTNGP09.phx.gbl...
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...


Each task has it's instruments. an interesting article about .net
applications:
http://www.sysinternals.com/blog/200...im-scared.html

--
Vladimir
Dec 11 '05 #14

P: n/a
"Greg" <gm@mcpherran.com> wrote in message
news:0B**********************************@microsof t.com...
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.

--
Vladimir
Dec 11 '05 #15

P: n/a
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!

"Scherbina Vladimir" <vl****************@gmail.com> wrote in message
news:uv*************@TK2MSFTNGP09.phx.gbl...
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uE*************@TK2MSFTNGP09.phx.gbl...
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...


Each task has it's instruments. an interesting article about .net
applications:
http://www.sysinternals.com/blog/200...im-scared.html

--
Vladimir

Dec 12 '05 #16

P: n/a
Marc Noon wrote:
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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 12 '05 #17

P: n/a
Jon Skeet [C# MVP] wrote:
Marc Noon <no***@bellsouth.net> wrote:

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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 12 '05 #18

P: n/a

"Richard Grimes" <ri******@mvps.org> wrote in message
news:eR**************@TK2MSFTNGP14.phx.gbl...
Marc Noon wrote:
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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm


Richard,

Note that the topic is C# vs. C++, if you run your FFT using C# you will
notice a performance drop compared to managed C++ (I guess you are refering
to C++/CLI) . This is the result of a slightly better optimization done by
the managed C++ compiler.

Willy.
Dec 12 '05 #19

P: n/a
"John Timney ( MVP )" <ti*****@despammed.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 12 '05 #20

P: n/a
Scherbina Vladimir wrote:
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:uE*************@TK2MSFTNGP09.phx.gbl...
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...


Each task has it's instruments. an interesting article about .net
applications:
http://www.sysinternals.com/blog/200...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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 12 '05 #21

P: n/a
Willy Denoyette [MVP] wrote:
Note that the topic is C# vs. C++, if you run your FFT using C# you
will notice a performance drop compared to managed C++ (I guess you
are refering to C++/CLI) . This is the result of a slightly better
optimization done by the managed C++ compiler.


OK, if you insist, however, I don't thjink it is necessary because I
think the performance is determined by the runtime and not by the
Microsoft .NET compilers.

I have converted the managed C++ FFT routine over to C# and I have
repeated the tests. These results show that the not optimised C# library
is just slower than the not optimised C++ library, but the optimised C#
is slightly faster than the optimised managed C++ library. The
difference in the optimised librarys is very small. This reinforces the
point in the article that the *runtime* does the optimizations, and that
the optimizations provided by the .NET compilers are marginal.

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

Please don't suggest I repeat the test with VB.NET, I refuse to touch
that language. <g>

Richard
--
Fusion Tutorial:
http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm

Dec 12 '05 #22

P: n/a
Cant remember where the figure came from but I'm sure it was at a Redmond
presentation, anyway - I'm glad you enlightened me with research Richard.
The figures you quote will be useful in the future.

In my case 4% for 2 billion computations does count very much and they are
extremely large numbers involved in intense mathematical computations. In
this instance I have no choice but to consider those minor percentages. I
do however entirely agree with your point though, typically 4% is really
negligable, especially when you weight up the benefits of turnaround time
for development.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Richard Grimes" <ri******@mvps.org> wrote in message
news:uE**************@TK2MSFTNGP14.phx.gbl...
"John Timney ( MVP )" <ti*****@despammed.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial: http://www.grimes.demon.co.uk/workshops/securityWS.htm

Dec 12 '05 #23

P: n/a
I'm impressed by your benchmarks... really. However, keep in mind that
you're comparing managed C++ versus unmanaged C++, but Redmond has
always claimed that managed C++ is faster than managed C# due to better
optimizing done by the C++.NET compiler.

That said, the last word I heard is that starting with .NET 2.0 they
would be concentrating their efforts on introducing better optimization
at the JIT stage, so any differences between the two managed languages
should diminish in the future.

Dec 12 '05 #24

P: n/a

"Richard Grimes" <ri******@mvps.org> wrote in message
news:e$**************@TK2MSFTNGP15.phx.gbl...
Willy Denoyette [MVP] wrote:
Note that the topic is C# vs. C++, if you run your FFT using C# you
will notice a performance drop compared to managed C++ (I guess you
are refering to C++/CLI) . This is the result of a slightly better
optimization done by the managed C++ compiler.
OK, if you insist, however, I don't thjink it is necessary because I think
the performance is determined by the runtime and not by the Microsoft .NET
compilers.

Agreed, the differences between C# and managed C++ (I've compiled to managed
code using /clr:safe) are extremely small, here it's C# which is the fastest
~5% compared with managed C++.

[my results using v2.0]
Average for native code: 9780,000 µseconds
Average for managed C++ code: 10820 µseconds
Average for managed C# code: 10272 µseconds

Other benchmarks I ran show the same pattern, sometimes C# is faster
sometimes it's slower, but the delta's remain within the +/-5% ranges. It's
also great to see the difference between native and managed getting smaller
from v1.x and v2.
I have converted the managed C++ FFT routine over to C# and I have
repeated the tests. These results show that the not optimised C# library
is just slower than the not optimised C++ library, but the optimised C# is
slightly faster than the optimised managed C++ library. The difference in
the optimised librarys is very small. This reinforces the point in the
article that the *runtime* does the optimizations, and that the
optimizations provided by the .NET compilers are marginal.

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

Please don't suggest I repeat the test with VB.NET, I refuse to touch that
language. <g>


LOL.
Willy.
Dec 12 '05 #25

P: n/a
Hi Richard

I'm working on FFT project (from strach) for education purpose, I just
create nice time-domain waveform window and spectrum window and running
DFT at the moment. I would be interested to learn more of your FFT
experience in C# world.

Have you used FFTW (fastest fourier transform in the west)?, I was
wondering how you managed to setup interop service for the which is
written in C.

Is there way of keep track of the message, it does not seem to have
forward email if new message is added?.

Regards

Richard Grimes wrote:
Marc Noon wrote:
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
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm


Dec 13 '05 #26

P: n/a
ri***@onetel.com wrote:
I'm working on FFT project (from strach) for education purpose, I just
create nice time-domain waveform window and spectrum window and
running DFT at the moment. I would be interested to learn more of
your FFT experience in C# world.
Not very much <g> If you asked me that 12 years ago I would be able to
tell you *everything* about the routine and the theories current at the
time. But now, all I know is that it is a computationally intensive
algorithm.
Have you used FFTW (fastest fourier transform in the west)?, I was
wondering how you managed to setup interop service for the which is
written in C.


I haven't used it. But the procedure is not a problem. The project on my
site shows three approaches.

1) Identify the 'main' entry point in the library and add extern "C"
__declspec(dllexport) to it, and then compile the library as a DLL. Then
use platform invoke to call it from C#.

2) Identify the 'main' entry point make this a public static method of a
public type and compile it as managed C++. Access the assembly as you
would access any other assembly from C#.

3) Convert the entire code to C#. This is perhaps the least best option,
but if the code does not use the CRT (maths routines excepted), nor uses
pointers, and only uses array syntax then it should not be too
difficult. The conversion of the project on my site took about 15
minutes. Pay particular attention to long - in C this is 32 bits, in C#
it is 64 bits.

Richard
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 13 '05 #27

P: n/a
Regarding performance, I would hope that floating point (i.e. float, double)
math operations in .NET will still use the math hardware in the CPU. I.e. the
runtime layer, even though not native, will still access hardware facilities
as needed?

Dec 21 '05 #28

P: n/a
Greg <gm@mcpherran.com> wrote:
Regarding performance, I would hope that floating point (i.e. float, double)
math operations in .NET will still use the math hardware in the CPU. I.e. the
runtime layer, even though not native, will still access hardware facilities
as needed?


It will certainly still do the operations in hardware - but whether the
JIT has long enough to work out whether it can parallelise operations
using SSE or the like is a different matter. I wouldn't like to
speculate on whether it does or not, but that's an area a static
compiler *might* get an advantage in. (That's not to say that any such
advantage will stay around forever, of course.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 21 '05 #29

P: n/a
Thank you.
It will certainly still do the operations in hardware...
Isn't this another example of why the fuss about even native C++ performance
over C# is overrated. I.e. it still comes down to hardware for a lot of the
number crunching and graphics display.

--
Greg McPherran
www.McPherran.com
"Jon Skeet [C# MVP]" wrote:
Greg <gm@mcpherran.com> wrote:
Regarding performance, I would hope that floating point (i.e. float, double)
math operations in .NET will still use the math hardware in the CPU. I.e. the
runtime layer, even though not native, will still access hardware facilities
as needed?


It will certainly still do the operations in hardware - but whether the
JIT has long enough to work out whether it can parallelise operations
using SSE or the like is a different matter. I wouldn't like to
speculate on whether it does or not, but that's an area a static
compiler *might* get an advantage in. (That's not to say that any such
advantage will stay around forever, of course.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 21 '05 #30

P: n/a
Greg <gm@mcpherran.com> wrote:
It will certainly still do the operations in hardware...


Isn't this another example of why the fuss about even native C++ performance
over C# is overrated. I.e. it still comes down to hardware for a lot of the
number crunching and graphics display.


Well, not entirely. If a native compiler can use parallelism in a way
that the JIT can't, the performance difference could be enormous. It's
unlikely to affect most applications, however.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 21 '05 #31

P: n/a
Theorically speaking JITed software could even be faster because:
1. they are, after all, fully compiled (by the JIT) as well
2. the JIT could optimize the code for the current hardware.

It's not true because because some CPU/Memory hungry optimization are not
done by the JIT while they are done by the native compiler.
But, in fact, unoptimized native C++ could be much slower than C# code.
For reference look at that Article by Richard Grimes
http://www.grimes.demon.co.uk/dotnet/man_unman.htm

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
"Greg" <gm@mcpherran.com> wrote in message
news:65**********************************@microsof t.com...
Thank you.
It will certainly still do the operations in hardware...


Isn't this another example of why the fuss about even native C++
performance
over C# is overrated. I.e. it still comes down to hardware for a lot of
the
number crunching and graphics display.

--
Greg McPherran
www.McPherran.com
"Jon Skeet [C# MVP]" wrote:
Greg <gm@mcpherran.com> wrote:
> Regarding performance, I would hope that floating point (i.e. float,
> double)
> math operations in .NET will still use the math hardware in the CPU.
> I.e. the
> runtime layer, even though not native, will still access hardware
> facilities
> as needed?


It will certainly still do the operations in hardware - but whether the
JIT has long enough to work out whether it can parallelise operations
using SSE or the like is a different matter. I wouldn't like to
speculate on whether it does or not, but that's an area a static
compiler *might* get an advantage in. (That's not to say that any such
advantage will stay around forever, of course.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Dec 22 '05 #32

P: n/a
> > I have converted the managed C++ FFT routine over to C# and I have
repeated the tests. These results show that the not optimised C# library
is just slower than the not optimised C++ library, but the optimised C# is
slightly faster than the optimised managed C++ library. The difference in
the optimised librarys is very small. This reinforces the point in the
article that the *runtime* does the optimizations, and that the
optimizations provided by the .NET compilers are marginal.


Agreed.


Bingo! This tells me right here that for .NET there is no good reason to use
C++ if one is more productive in C#. Thank you will Richard and Willy.

Dec 29 '05 #33

P: n/a
Anyone can answer my question?
-- In C#, one can use
new Object [,] {{"name","=","Yuje"}, {"ID","=","1"}} to represent "where"
in SQL select, But what about in C++

Can we say

Object *obj[] ={{"name","=","Yuje"}, {"ID","=","1"}} ?
What was the corresponding of C++ to C# in this case.

--
Yuje Peng
Yuje Peng
"Greg" wrote:
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?

--
Greg McPherran
www.McPherran.com

Mar 15 '06 #34

This discussion thread is closed

Replies have been disabled for this discussion.