HighTechTalks DotNet Forums  

C# vs C

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss C# vs C in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: C# vs C - 11-21-2006 , 02:37 PM






Kevien Lee <ironpythonster (AT) gmail (DOT) com> wrote:
Quote:
As calculation library ,use the C# may be not a good idea
The c# which is fit for RAD ,especial in enterprise develop,
but if you write a calculation library ,if would be become so
slowly.
In many cases, the C# code will be JIT compiled down to very similar
assembly. There *are* situations where C can outperform C#
significantly, but don't assume that just because calculations are
involved, C# will be significantly slower.

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


Reply With Quote
  #12  
Old   
Ben Voigt
 
Posts: n/a

Default Re: C# vs C - 11-24-2006 , 11:37 AM







"Sergei Gnezdov" <check reply to and replace (at) with @> wrote

Quote:
Frequent interop calls will reduce the overall speed of the native
implementation. Thus .NET implementation might not look that slow after
all.
I wouldn't say once per second is frequent enough for the marshalling
overhead be a concern.

Quote:
If you had few native calls that take a while the chance that native calls
are faster would've been higher, but that is not your case.

"barcel" <i99marda (AT) island (DOT) liu.se> wrote in message
news:1164059091.127072.22660 (AT) m73g2000cwd (DOT) googlegroups.com...
Thanks for the input.

To shed some light on what is going on I can say that the c-function is
doing calculations almost "all the time", i.e. it is called frequently.
Every second or so...

The amount of data differ, but perhaps on average there will be some
five arrays of doubles with a length of 50-100 each.

So I take it that the C# implementation is not significantly slower.
That means it comes down to maintainability. Having two code bases is
never good so I guess calling the C DLL will do. Or do you think of it
differently? Of course I will do some performance tests as well...

Cheers





Reply With Quote
  #13  
Old   
Ben Voigt
 
Posts: n/a

Default Re: C# vs C - 11-24-2006 , 11:39 AM




"barcel" <i99marda (AT) island (DOT) liu.se> wrote

Quote:
Hi,

I have a calculation library written in C compiled into a DLL. I now
need to move into the .NET world and would like som advise on this.

One option would be to keep the C-code in the current dll and call it
directly from C#. This would require marshalling of some structs etc
which could be done in a wrapper class in C#.
If you are going to write a wrapper, you may wish to use C++/CLI for that.

Quote:
The other option would be to convert all code into .NET and retire the
DLL. This I could do, but I am worried that the .NET implementation
won't be as fast as the C implementation, even taking the marshalling
into account.
C++/CLI "It Just Works" marshalling is far faster than p/invoke from C#.

Quote:
Would be nice if somebody could do some consulting here....

thanks,




Reply With Quote
  #14  
Old   
Robert Hooker
 
Posts: n/a

Default Re: C# vs C - 12-07-2006 , 05:54 PM



This excellent article (http://www.grimes.demon.co.uk/dotnet/man_unman.htm)
shows that for 'calculation' based code such as yours, managed C# can be
FASTER than C/C++.
My informal experience backs this up as well.

Rob

"barcel" <i99marda (AT) island (DOT) liu.se> wrote

Quote:
Hi,

I have a calculation library written in C compiled into a DLL. I now
need to move into the .NET world and would like som advise on this.

One option would be to keep the C-code in the current dll and call it
directly from C#. This would require marshalling of some structs etc
which could be done in a wrapper class in C#.

The other option would be to convert all code into .NET and retire the
DLL. This I could do, but I am worried that the .NET implementation
won't be as fast as the C implementation, even taking the marshalling
into account.

Would be nice if somebody could do some consulting here....

thanks,




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.