Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old August 27th, 2007, 04:55 PM
Joe
Guest
 
Posts: n/a
Default .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.

  #2  
Old August 27th, 2007, 05:05 PM
Phlip
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

Joe wrote:
Quote:
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
  #3  
Old August 27th, 2007, 05:25 PM
Joe
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

Okay.

Compiling to MSIL (.NET code produced by CLR) is very fast yes.
Quote:
Declaring all your math in a template
What do you mean? I am a C++ dummy!

  #4  
Old August 27th, 2007, 05:25 PM
Phlip
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

Joe wrote:
Quote:
Compiling to MSIL (.NET code produced by CLR) is very fast yes.
>
Quote:
>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
  #5  
Old August 27th, 2007, 05:55 PM
Joe
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

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.

  #6  
Old August 27th, 2007, 06:15 PM
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

On 2007-08-27 18:48, Joe wrote:
Quote:
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
  #7  
Old August 27th, 2007, 07:25 PM
Joe
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

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

  #8  
Old August 27th, 2007, 07:25 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

Joe wrote:
Quote:
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


  #9  
Old August 27th, 2007, 07:25 PM
Joe
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

Victor, your right. Sorry.

  #10  
Old August 27th, 2007, 07:35 PM
Phlip
Guest
 
Posts: n/a
Default Re: .NET versus C++ compiled code

Joe wrote:
Quote:
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/
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,338 network members.