.NET versus C++ compiled code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    .NET versus C++ compiled code

    Hi,

    I am looking to start a brand new project. Yeahhh! ;-)


    The code will do a lot of processor intensive processing. I mean a
    lot
    of loops to archieve big calculations. You know recursive functions
    and everything. Since I am a .NET programmer I have a question. Is
    there a real big difference in term of performance (based on the
    processors we have in our machine nowadays) between a .NET (C#)
    program and the same one written in C++ compiled with Microsoft or
    Borland C++ compiler.


    I know that is a big question! Probably that too much factors can
    influence the overall result.


    Thanks.

  • Peter Duniho

    #2
    Re: .NET versus C++ compiled code

    Joe wrote:
    [...]
    Is
    there a real big difference in term of performance (based on the
    processors we have in our machine nowadays) between a .NET (C#)
    program and the same one written in C++ compiled with Microsoft or
    Borland C++ compiler.
    >
    I know that is a big question! Probably that too much factors can
    influence the overall result.
    My experience has been that the overhead is much smaller than I would
    have expected before I started doing .NET programming a few years ago.
    Under normal conditions, where the code is not entirely CPU-bound, the
    overhead is practically invisible, because the code is mostly waiting
    for other things anyway.

    If you have code that _is_ completely CPU-bound, you may be able to
    measure a difference. If that code takes a long time to run, that
    difference may translate to a genuinely noticeable delay. But it's
    impossible to say in advance what sort of exact difference you might
    notice without knowing the specifics of your algorithm.

    Also in my experience, it has been true that if something needs speeding
    up, usually the first place to start is fixing the algorithm, which is
    almost never written optimally to start with. You might speed something
    up by 10-25% (depending on a variety of factors) moving code to C++,
    whereas fixing the algorithm can often speed things up by 50%, 100%, or
    more. Algorithm problems are much more common than platform problems.

    There are always exceptions, of course, but those will only be
    identified by first making sure you have the most optimal algorithm, and
    then doing an actual comparison between the C# and C++ versions of the
    algorithm. It's impossible to say in advance what difference, if any,
    there might be.

    Pete

    Comment

    • =?iso-8859-1?q?Horacio_Nu=F1ez_Hern=E1ndez?=

      #3
      Re: .NET versus C++ compiled code

      On 27 ago, 09:24, Joe <jonathanpou... @globetrotter.n etwrote:
      Hi,
      >
      I am looking to start a brand new project. Yeahhh! ;-)
      >
      The code will do a lot of processor intensive processing. I mean a
      lot
      of loops to archieve big calculations. You know recursive functions
      and everything. Since I am a .NET programmer I have a question. Is
      there a real big difference in term of performance (based on the
      processors we have in our machine nowadays) between a .NET (C#)
      program and the same one written in C++ compiled with Microsoft or
      Borland C++ compiler.
      >
      I know that is a big question! Probably that too much factors can
      influence the overall result.
      >
      Thanks.
      The CLR spent some time compiling the IL to native, but this is only
      the first a function is called but the .NET allocation of objects is
      more efficient that the traditional C++. As you say there are ver
      factors. Anyway you can compile the application for an especial
      plataform, an generate a native code instead an IL.
      Another issue can be create some functions in c++ and interop later.
      Or you can try the C++/CLI language and have both managed an umnanaged
      shipping the best of two worlds

      The desicion is yours!

      regards

      Comment

      • Ben Voigt [C++ MVP]

        #4
        Re: .NET versus C++ compiled code


        "Horacio Nuñez Hernández" <hnh12358@gmail .comwrote in message
        news:1188234591 .602148.59970@k 79g2000hse.goog legroups.com...
        On 27 ago, 09:24, Joe <jonathanpou... @globetrotter.n etwrote:
        >Hi,
        >>
        >I am looking to start a brand new project. Yeahhh! ;-)
        >>
        >The code will do a lot of processor intensive processing. I mean a
        >lot
        >of loops to archieve big calculations. You know recursive functions
        >and everything. Since I am a .NET programmer I have a question. Is
        >there a real big difference in term of performance (based on the
        >processors we have in our machine nowadays) between a .NET (C#)
        >program and the same one written in C++ compiled with Microsoft or
        >Borland C++ compiler.
        >>
        >I know that is a big question! Probably that too much factors can
        >influence the overall result.
        >>
        >Thanks.
        >
        The CLR spent some time compiling the IL to native, but this is only
        the first a function is called but the .NET allocation of objects is
        more efficient that the traditional C++. As you say there are ver
        factors. Anyway you can compile the application for an especial
        plataform, an generate a native code instead an IL.
        Another issue can be create some functions in c++ and interop later.
        Or you can try the C++/CLI language and have both managed an umnanaged
        shipping the best of two worlds
        Please note that the Microsoft C++ compiler (used also for C++/CLI) does a
        lot of optimizations not supported by C#.

        However, for code heavy on recursive functions, you should definitely
        consider a functional language, where the optimizers are written
        specifically to deal with recursion.


        Comment

        • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

          #5
          Re: .NET versus C++ compiled code

          Joe wrote:
          The code will do a lot of processor intensive processing. I mean a
          lot
          of loops to archieve big calculations. You know recursive functions
          and everything. Since I am a .NET programmer I have a question. Is
          there a real big difference in term of performance (based on the
          processors we have in our machine nowadays) between a .NET (C#)
          program and the same one written in C++ compiled with Microsoft or
          Borland C++ compiler.
          Even for CPU intensive code I would expect the .NET code to
          be almost as fast as the native code - within 20% of the
          C++ compiler (with maximum optimization - C# will be faster
          than default C++ compiler options). But for a few cases it
          is possible to code C++ in a way that are much faster than C#
          sometimes 2-3 times as fast. Whether you code contain
          examples of that is impossible to say upfront.

          Arne

          Comment

          • Micky Duncan

            #6
            Re: .NET versus C++ compiled code

            Hi,
            I once ported my c++ ray tracer to c# and found that the c# code was
            approximately 10% slower than c++. Ray tracing is probably once of the most
            recursive algorithms and is quite heavy on floating point and math - lots of
            sqrt() and such.

            Though performance is generally paramount in Ray tracing, the productivity
            gain in writing in c# over c++ I am willing to lose that small performance
            loss.

            Besides, I can always fine tune some aspects and write in c++ interop.

            --
            Cheers,
            Micky D

            "Joe" <jonathanpoulin @globetrotter.n etwrote in message
            news:1188231840 .257395.28720@d 55g2000hsg.goog legroups.com...
            Hi,
            >
            I am looking to start a brand new project. Yeahhh! ;-)
            >
            >
            The code will do a lot of processor intensive processing. I mean a
            lot
            of loops to archieve big calculations. You know recursive functions
            and everything. Since I am a .NET programmer I have a question. Is
            there a real big difference in term of performance (based on the
            processors we have in our machine nowadays) between a .NET (C#)
            program and the same one written in C++ compiled with Microsoft or
            Borland C++ compiler.
            >
            >
            I know that is a big question! Probably that too much factors can
            influence the overall result.
            >
            >
            Thanks.
            >

            Comment

            Working...