.NET versus C++ compiled code

J

Joe

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.
 
P

Phlip

Joe said:
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.
 
P

Phlip

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


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
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

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>();
 
J

Joe

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

Victor Bazarov

Joe said:
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
 
P

Phlip

Joe said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top