.NET versus C++ compiled code

Discussion in 'C++' started by Joe, Aug 27, 2007.

  1. Joe

    Joe Guest

    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.
    Joe, Aug 27, 2007
    #1
    1. Advertising

  2. Joe

    Phlip Guest

    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.


    Look up "Template Metaprogramming", starting with Boost.

    In a nutshell, you trade very long compile times for very short execution
    time. Declaring all your math in a template allows the compiler to squeeze
    everything down to a solid brick of aggressively optimized opcodes.

    --
    Phlip
    http://www.oreilly.com/catalog/9780596510657/
    ^ assert_xpath
    http://tinyurl.com/23tlu5 <-- assert_raise_message
    Phlip, Aug 27, 2007
    #2
    1. Advertising

  3. Joe

    Joe Guest

    Okay.

    Compiling to MSIL (.NET code produced by CLR) is very fast yes.

    > Declaring all your math in a template


    What do you mean? I am a C++ dummy!
    Joe, Aug 27, 2007
    #3
  4. Joe

    Phlip Guest

    Joe wrote:

    > Compiling to MSIL (.NET code produced by CLR) is very fast yes.
    >
    >> Declaring all your math in a template

    >
    > What do you mean? I am a C++ dummy!


    Look up template.

    Then look up template metaprogramming.

    It trades execution time for compile time. So you get a slow compile,
    because the compiler is doing as much math as it can at compile time. Not
    at runtime, where you don't want it

    --
    Phlip
    http://www.oreilly.com/catalog/9780596510657/
    ^ assert_xpath
    Phlip, Aug 27, 2007
    #4
  5. Joe

    Joe Guest

    Joe, Aug 27, 2007
    #5
  6. On 2007-08-27 18:48, Joe wrote:
    > Okay. I found it about the subject: http://en.wikipedia.org/wiki/Template_metaprogramming
    >
    > I love Wikipedia!
    >
    > But since it's a C++ group maybe you are ignoring if C# support
    > template metaprogramming. Probably not.


    C# have something called Generics which is not the same thing as C++
    templates, it is not as powerful as templates and it's a run-time thing,
    which means that you can't get the same performance boost as templates
    can give you. If you are used to C# you've probably used generics
    already, you usually encounter them when dealing with collections and
    they can be identified by the usage of < and >, like so

    List<int> = new List<int>();

    --
    Erik Wikström
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Aug 27, 2007
    #6
  7. Joe

    Joe Guest

    Yes Erik, I used them that way. So there is no way to use Generics the
    way template works in C++?
    Joe, Aug 27, 2007
    #7
  8. Joe wrote:
    > Yes Erik, I used them that way. So there is no way to use Generics the
    > way template works in C++?


    Please consider asking C# questions in a C# newsgroup.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 27, 2007
    #8
  9. Joe

    Joe Guest

    Victor, your right. Sorry.
    Joe, Aug 27, 2007
    #9
  10. Joe

    Phlip Guest

    Joe wrote:

    > Yes Erik, I used them that way. So there is no way to use Generics the
    > way template works in C++?


    Templates in C++ have a very strict definition, almost like macros. They are
    not the same as the systems in other languages that make classes into
    objects, for example. This strict definition allows a compiler to squeeze
    the code down very far.

    Many languages need the other abilities of templates, so they get them using
    a softer definition that doesn't permit these optimizations.

    --
    Phlip
    http://www.oreilly.com/catalog/9780596510657/
    Phlip, Aug 27, 2007
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Ry5ILkxhd3JlbmNl?=

    compiled dll's versus aspx.cs

    =?Utf-8?B?Ry5ILkxhd3JlbmNl?=, Apr 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,624
    Kevin Spencer
    Apr 7, 2004
  2. Russ

    script versus code versus ?

    Russ, Jun 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,494
  3. Klaus Schneider
    Replies:
    1
    Views:
    539
    Rolf Magnus
    Dec 2, 2004
  4. lander
    Replies:
    5
    Views:
    586
    bruce barker
    Mar 5, 2008
  5. Paul Butcher
    Replies:
    12
    Views:
    703
    Gary Wright
    Nov 28, 2007
Loading...

Share This Page